根据https://stackoverflow.com/a/33042872/4106030 https://stackoverflow.com/a/33042872/4106030我们不应该使用@Profile
让 spring 配置文件决定是否执行或忽略测试类中的所有测试。
有如下规定:
@Profile
用于选择性地启用组件(例如,@Service
, ETC。),@Configuration
类,或@Bean
方法(如果指定 bean 定义配置文件之一在 ApplicationContext 的 Spring 环境中处于活动状态)。该注释与测试没有直接关系:@Profile
不应该在测试类上使用.
这是真的?如果是的话为什么?
这是真的,因为@Profile
影响 Spring 组件并没有连接到 Test 框架。
尽管如此,您可以拥有测试配置文件,它将在运行测试时加载 Spring 组件(作为配置类)
带有配置文件的测试类示例:
// load related configuration classes
@ContextConfiguration(classes = { TestConfiguration.class })
@ActiveProfiles(profiles = { "testing" })
public class MyTest extends AbstractTestNGSpringContextTests {
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)