在我的测试类中,我有一个@SpringBootTest,它的工作原理是这样的:
@ContextConfiguration(classes = ClassA.Config.class )
@SpringBootTest
class ClassATest {
@Autowired
SomePropertiesProvider provider;
@DynamicPropertySource
private static void registerProperties(DynamicPropertyRegistry registry) {
registry.add("project.random.configuration", () -> "random_value");
}
@Test
void a_test() {
// any stuff
}
@Configuration
@EnableAutoConfiguration(exclude = {AnyAutoConfiguration.class})
@ComponentScan( basePackages = "package")
static class Config {
}
它工作正常,但是之后,我在其他类中进行了其他集成测试,这不是 @SpringBootTest
有一个由 @BeforeAll 注释的方法,它的工作方式如下:
@BeforeAll
static void beforeAll() throws IOException, URISyntaxException {
if (System.getProperty("api.base-url") == null) {
MONGO_DB_CONTAINER.start();
MOCK_SERVER_CONTAINER.start();
ORCHESTRATOR_CONTAINER.start();
SpringApplication app = new SpringApplication(Application.class);
app.addInitializers(new Initializer());
applicationContext = app.run();
dbInitialization();
}
}
事实上,第一个类“exclude = {AnyAutoConfiguration.class}”的排除还在,让这段代码失效。如何为最后一次测试删除此排除项?
提前致谢。