Maven / TestNG报告“失败:0”,然后“有测试失败。”,出了什么问题?

时间:2011-02-17 10:41:19

标签: maven-2 maven testng surefire

我在Win XP上使用Maven 2.2.1 r801777,Surefire 2.7.1,TestNG 5.14.6,Java 1.6.0_11。

我只有一个带有一个空测试方法的测试类,而在我的pom中,我刚刚添加了TestNG依赖项。当我执行mvn test时,它打印出来:

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

Results :

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

[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] There are test failures.

Please refer to [...]\target\surefire-reports for the individual test results.

测试报告和-e切换时没有错误:

[INFO] Trace
org.apache.maven.BuildFailureException: There are test failures.

Please refer to [...]\target\surefire-reports for the individual test results.
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:715)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
        at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoFailureException: There are test failures.

Please refer to [...]\target\surefire-reports for the individual test results.
        at org.apache.maven.plugin.surefire.SurefirePlugin.execute(SurefirePlugin.java:575)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
        ... 17 more

有什么想法吗?


修改

我的pom:

<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.sample</groupId>
    <artifactId>sample</artifactId>
    <name>sample</name>
    <packaging>jar</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <description />

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>5.14.6</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

我唯一的课程:

import org.testng.Assert;
import org.testng.annotations.Test;
@Test
public class MyTest {
    @Test
    public void test() {
        Assert.assertEquals("a", "a");
    }
}

2 个答案:

答案 0 :(得分:2)

刚刚用pom文件创建了简单的示例项目(修复了一些部分)并将其放在github上...使用Maven 2.2.1测试并且Maven 3.0.2完美无缺。问题的原因必须在其他地方......

答案 1 :(得分:0)

如下所示,请指定surefire插件版本(如果您遇到相同问题,则为2.4.1),并指定forkmode和useManifestOnlyJar值

    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <forkMode>none</forkMode><!-- 'none' is so we can debug -->
                <argLine>-enableassertions</argLine>
                <!--
                <useManifestOnlyJar>false</useManifestOnlyJar>
                <useSystemClassLoader>true</useSystemClassLoader>
                -->
                <suiteXmlFiles>
                    <suiteXmlFile>
                        ${basedir}/src/main/resources/testng-none.xml
                    </suiteXmlFile>
                </suiteXmlFiles>

            </configuration>

        </plugin>