使用Maven命令行强制运行@ Ignore'd JUnit测试

Jos*_*ger 13 junit maven

我有一个带有@Ignore属性的JUnit测试,例如 -

public class HealthCareGov
{
    @Test
    @Ignore
    public void performancetest()
    {
        // stuff
    }
}
Run Code Online (Sandbox Code Playgroud)

在大多数IDE(例如IntelliJ)中,即使存在@Ignore属性,也可以通过选择方法名称来强制运行此测试.我猜Eclipse也允许这个?

但是,当我尝试通过执行以下操作在Maven中执行相同的行为时 -

mvn -Dtest=HealthCareGov#performancetest test
Run Code Online (Sandbox Code Playgroud)

似乎Maven跳过了测试.这是输出 -

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running HealthCareGov
Tests run: 1, Failures: 0, Errors: 0, Skipped: 1, Time elapsed: 0.032 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 1
Run Code Online (Sandbox Code Playgroud)

我可以使用什么Maven命令行来强制执行此测试以重现我的IDE生成的行为?修改Java源代码不是一种选择.

jor*_*gos 7

这可以添加到测试中.

@IfProfileValue(name="test-profile", value="IntegrationTest")
public class PendingChangesITCase extends AbstractControllerIntegrationTest {
    ...
}
Run Code Online (Sandbox Code Playgroud)

要选择要执行的测试,只需将值添加到配置文件以执行集成测试.

<properties>
    <test-profile>IntegrationTest</test-profile>
</properties>
Run Code Online (Sandbox Code Playgroud)

此外,您可以使用命令行来设置test-profile变量:

mvn -Dtest-profile=IntegrationTest
Run Code Online (Sandbox Code Playgroud)

  • 为了完整起见..这需要包含spring-test jar和以下注释@RunWith(SpringJUnit4ClassRunner.class)@IfProfileValue(name ="test-profile",value ="IntegrationTest")@ContextConfiguration(locations ="<your- spring.xml>") (2认同)