3

我们正在使用 Maven 3.0.3 并正在使用 JUnit 4.8.1 ...

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
        <scope>test</scope>
    </dependency>

我们有这个测试文件...

./src/test/java/com/myco/clearing/common/xml/TextNodeTest.java

我怎样才能运行这个单独的测试?当我尝试

mvn -Dtest=TextNodeTest test

我收到一条错误消息,说没有运行任何测试。如果我为我的测试指定整个包名,我会得到同样的错误。...

mvn clean -Dtest=com.myco.clearing.common.xml.TextNodeTest test

这会产生错误消息...

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project myco-productplus-web: No tests were executed!
(Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

这是我正在使用的万无一失的配置

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.12</version>
            <configuration>
                <skip>false</skip>
                <additionalClasspathElements>
                    <additionalClasspathElement>${project.build.sourceDirectory}</additionalClasspathElement>
                    <additionalClasspathElement>${project.build.testSourceDirectory}</additionalClasspathElement>
                </additionalClasspathElements>
                <useManifestOnlyJar>false</useManifestOnlyJar>
                <forkMode>always</forkMode>
                <systemProperties>
                    <property>
                        <name>gwt.args</name>
                        <value>-out "${webappDirectory}"</value>
                    </property>
                </systemProperties>
                <systemPropertyVariables>
                    <tomcat.port>${tomcat.servlet.port}</tomcat.port>
                    <project.artifactId>${project.artifactId}</project.artifactId>
                </systemPropertyVariables>
            </configuration>
        </plugin>
4

3 回答 3

6

在surefire中运行单个测试(方法)的方法是:

mvn test -Dtest=uk.co.farwell.AppTest#testSlow

注意 # 而不是类名和方法名之间的空格。

但是,正如@Andrew 所说,2.12 中存在一个错误(SUREFIRE-827:Surefire 2.12 无法运行单个测试,从 2.11 回归),但它在 2.11 中有效。

上述错误仍然存​​在(截至 2012 年 2 月 24 日),但实际上使用 2.13-SNAPSHOT 对我有用。

编辑:现在在 2.12.1 中将其标记为已修复。

于 2012-02-23T23:22:19.873 回答
2

看起来这是 2.12 版本中的一个错误 - SUREFIRE-827。尝试降级到 2.11。

于 2012-02-18T07:04:37.663 回答
0

就像其他人说的那样,这是 Surefire 中的一个错误,自 2.11.1 版本以来已修复

于 2012-08-22T14:51:00.060 回答