Java 使用Spring和@IfProfileValue如何仅获取要运行的特定方法
我有一个测试类和pom,如下所示: 当我运行maven命令Java 使用Spring和@IfProfileValue如何仅获取要运行的特定方法,java,spring,maven,junit,Java,Spring,Maven,Junit,我有一个测试类和pom,如下所示: 当我运行maven命令mvn clean test-Dtest.profile.discriminator=Twitter时,我的目标只是让testNumber2()运行,因为它是唯一一个具有适当的test.profile.discriminator的测试,然而,我却让类中的所有测试都运行(1,2,3) 我如何才能做到这一点?您需要在类中添加以下注释 @RunWith(SpringJUnit4ClassRunner.class) @ContextConfig
mvn clean test-Dtest.profile.discriminator=Twitter
时,我的目标只是让testNumber2()
运行,因为它是唯一一个具有适当的test.profile.discriminator
的测试,然而,我却让类中的所有测试都运行(1,2,3)
我如何才能做到这一点?您需要在类中添加以下注释
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = YourConfig.class /* or some xml file */)
@ProfileValueSourceConfiguration
因此JUnit使用Spring的测试运行程序,而不是默认的。删除
@test
注释。它们导致运行所有测试用例。我已经更新了我的要点:但它仍然有相同的反应(运行所有测试)@llaskin如果你不想运行其他方法,你必须用一个不在系统属性中的值添加一个@IfProfileValue
注释。