【发布时间】:2020-02-21 05:28:56
【问题描述】:
我有几个 @Component 注释类,我在其中初始化了我的配置器,例如 DBConfigurer、SecurityConfigurer、JmxConfigurer 等等。
在添加功能测试时,我希望不应该加载几个类。我可以排除上面定义的几个配置器吗?
我的测试类我定义如下:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = { ServiceStarter.class }, properties = { "jmx.rmi.port=19057", "hostname=localhost" })
@ContextConfiguration(classes = {ControllerTest.BeansOverrideConfigurer.class})
public class ControllerTest {
// All test here.
}
我可以在测试类的 @ContextConfiguration 块中定义选定的配置器,但我不想这样做,因为将来如果有人添加新的配置器,它应该会自动导入到测试用例中。
【问题讨论】:
标签: java junit annotations spring-boot-test