首页 > 解决方案 > 找不到@SpringBootConfiguration,需要使用@ContextConfiguration 或@SpringBootTest(classes=...)

问题描述

我有这个测试课。当我运行这个时,我收到了这个错误

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
@ActiveProfiles(value = "test")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class HealthGaugeMetricsIT {

    /**
     * MasterHealthMetricsReporter for creating the gauges.
     */
    @Autowired
    private MasterHealthMetricsReporter masterHealthMetricsReporter;

    /**
     * Holds meter registry instance.
     */
    @Autowired
    private MeterRegistry registry;

    /**
     * Test for creating the vault gauge and testing that it's bound
     * correctly.
     */
    @Test
    public void testVaultGauge ()
    {
        masterHealthMetricsReporter.bindTo(registry);
        final Gauge g = registry.get("encryption.sampleApp.health.vault").gauge();
        assertEquals("validating that vault gauge return the correct value",
            1.0, g.value(), 0.0);
    }
}

由于这个问题,我无法运行这个测试用例。验证包结构,包结构在 src/main/java 和 src/test/java 中是相同的。

标签: springspring-bootjunitdatadog

解决方案


推荐阅读