如何在SpringJunit4TestRunner中将@ComponentScan与测试特定的ContextConfiguration一起使用?

如何在SpringJunit4TestRunner中将@ComponentScan与测试特定的ContextConfiguration一起使用?,第1张

如何在SpringJunit4TestRunner中将@ComponentScan与测试特定的ContextConfiguration一起使用?

以下内容将通过引入一个仅适用于当前测试类的新

fake-communication
配置文件 来帮助您实现目标。

@RunWith(SpringJUnit4ClassRunner.class)@SpringApplicationConfiguration(classes = MyApplication.class)@WebAppConfiguration@ActiveProfiles({"test", "fake-communication"})public class Component1TestWithFakeCommunication {    // @Autowired ...    @Profile("fake-communication")    @Configuration    static class ContextConfiguration {        @Bean        @Primary        public ServiceClient mockedServiceClient() { return mock(ServiceClient.class);        }    }}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5639322.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存