使用Maven命令行强制运行@ Ignore'd JUnit测试 [英] Force run of @Ignore'd JUnit test using Maven command line

查看:136
本文介绍了使用Maven命令行强制运行@ Ignore'd JUnit测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a JUnit test with an @Ignore attribute, for example -

public class HealthCareGov
{
    @Test
    @Ignore
    public void performancetest()
    {
        // stuff
    }
}

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

In most IDEs (IntelliJ for example) I can forcefully run this test by selecting the method name even though there is an @Ignore attribute. I'm guessing Eclipse also allows this?

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

However, when I try to do the same behavior in Maven by executing the following -

mvn -Dtest=HealthCareGov#performancetest test

看来Maven跳过了测试.这是输出-

It appears that Maven skips the test. This is the output -

-------------------------------------------------------
 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

我可以使用哪个Maven命令行来强制执行该测试以重现IDE产生的行为?不能修改Java源代码.

What Maven command line can I use to force the execution of this test to reproduce the behavior that my IDE produces? Modifying the Java source code is not an option.

推荐答案

可以将其添加到测试中.

This can be added to the test.

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

要选择要执行的测试,只需将值添加到用于执行集成测试的配置文件中即可.

To select the tests to be executed just add the value to the profile for executing the integration tests.

<properties>
    <test-profile>IntegrationTest</test-profile>
</properties>

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

Also, you can use the command line to set the test-profile variable:

mvn -Dtest-profile=IntegrationTest

这篇关于使用Maven命令行强制运行@ Ignore'd JUnit测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆