Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Spring和@IfProfileValue如何仅获取要运行的特定方法_Java_Spring_Maven_Junit - Fatal编程技术网

Java 使用Spring和@IfProfileValue如何仅获取要运行的特定方法

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

我有一个测试类和pom,如下所示:

当我运行maven命令
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
注释。