Maven surefire 2.12不会使用-Dtest参数运行特定的测试 [英] Maven surefire 2.12 does not run a specific test using -Dtest parameter

查看:120
本文介绍了Maven surefire 2.12不会使用-Dtest参数运行特定的测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在为项目升级所有Maven插件版本后,我遇到以下问题:当运行基本命令mvn test -Dtest=SomeTest时,构建完成,根本没有执行任何测试.实际上,我无法使用-Dtest参数运行任何测试(当然该测试存在,并且仅在执行mvn test时运行).

After upgrading all my Maven plugins version for a project, I encountered the following problem: when I run the basic command mvn test -Dtest=SomeTest, the build finishes with no test executed at all. In fact, I am not able to run any test using -Dtest parameter (of course the test exist, and is run when I simply execute mvn test).

在进行一些搜索后,似乎是由于使用了 surefire 2.12 插件引起的问题.我已经测试了Maven(2.2.1/3.0.2)和JUnit(4.7.x,4.8、4.10甚至3.8.x)的多个版本,但是它们对我的问题没有影响.

After some searches, it appears that the problem is due to the usage of surefire 2.12 plugin. I've tested several versions of Maven (2.2.1 / 3.0.2) and JUnit (4.7.x, 4.8, 4.10, or even 3.8.x), but they have no impact on my issue.

那么,也许我的项目有一些特定的配置可能会对它产生影响?无论如何,我使用mvn archetype:generate(使用基本的 org.apache.maven.archetypes:maven-archetype-quickstart )创建了一个新项目.

So maybe my project has some specific configurations that may have an impact on that? Anyway, I created a new project, using mvn archetype:generate (using the basic org.apache.maven.archetypes:maven-archetype-quickstart).

我只修改了pom.xml中的两件事:使用JUnit 4.10(但它没有做任何更改,我尝试了其他版本),并定义了surefire的版本:

I modified only 2 things in the pom.xml: using JUnit 4.10 (but it didn't change anything, I've tried with others versions), and defining the version of surefire:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>foo</groupId>
    <artifactId>bar</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.11</version>
            </plugin>
        </plugins>
    </build>
</project>

我运行mvn test -Dtest=AppTest(原型创建的默认JUnit测试):

I run mvn test -Dtest=AppTest (the default JUnit test created by the archetype):

-------------------------------------------------------  T E S T S
------------------------------------------------------- Running foo.AppTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time
elapsed: 0.031 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO]
------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO]

现在,我修改pom.xml以将版本 2.12 用于Surefire并再次运行命令:

Now, I modify the pom.xml to use version 2.12 for Surefire and run the command again:

-------------------------------------------------------  T E S T S

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO]
------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO]
------------------------------------------------------------------------ [INFO] Total time: 0.907s [INFO] Finished at: Fri Mar 02 10:37:12 CET
2012 [INFO] Final Memory: 3M/15M [INFO]
------------------------------------------------------------------------ [ERROR] Failed to execute goal
org.apache.maven.plugins:maven-surefire-plugin:2.12:test
(default-test) on project bar: No tests were executed!  (Set -D
failIfNoTests=false to ignore this error.) -> [Help 1]

这次测试未运行:(

就我而言,我认为这是一种回归,但这非常令人惊讶.实际上,在Surefire 2.12版本中记录了 JIRA缺陷.成功使用-Dtest参数.

As far as I am concerned, I think it's a regression, but that's quite surprising. Indeed, a JIRA defect is logged on Surefire 2.12 version, and in this description, they succeed in using -Dtest parameter.

我做错什么了吗?还是真正的回归(在这种情况下,我将创建JIRA)?

Am I doing something wrong? Or is it a real regression (in this case, I will create the JIRA)?

谢谢.

推荐答案

这是2.12版中的错误- SUREFIRE-827 .

It's a bug in 2.12 version - SUREFIRE-827.

这篇关于Maven surefire 2.12不会使用-Dtest参数运行特定的测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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