相关疑难解决方法(0)

元注释中的@ActiveProfiles和测试类不起作用

我创建了一个元注释@EmbeddedMongoDBUnitTest,它激活了两个配置文件,用于基于弹簧的单元测试.基本设置有效:

@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@ActiveProfiles({"embeddedMongoDB", "embeddedMongoDBUnitTest"})
public @interface EmbeddedMongoDBUnitTest {
}

@RunWith(SpringJUnit4ClassRunner.class)
@EmbeddedMongoDBUnitTest
@ContextConfiguration(...)
public class WorkingTest {
    ...
}
Run Code Online (Sandbox Code Playgroud)

现在,当尝试使用测试类本身上的另一个@ActiveProfiles注释激活另一个配置文件时,@ EmbeddedMongoDBUnitTest中的配置文件不再被激活:

@RunWith(SpringJUnit4ClassRunner.class)
@EmbeddedMongoDBUnitTest
@ActiveProfiles({"h2IntegrationTests"})
@ContextConfiguration(...)
public class NotWorkingTest {
    ...
}
Run Code Online (Sandbox Code Playgroud)

有没有理由说这不起作用,或者这是春季测试代码中的错误?

junit spring annotations spring-test spring-annotations

4
推荐指数
1
解决办法
2861
查看次数