2011-02-17 58 views
2

我在Win XP上使用Maven 2.2.1 r801777,Surefire 2.7.1,TestNG 5.14.6,Java 1.6.0_11。Maven/TestNG报告“失败:0”,但随后出现“有测试失败”,出了什么问题?

我只有一个测试类与一个空的测试方法,并在我的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"); 
    } 
} 
+0

有您在测试课程中更新了您的导入。此外,你做了一些Assert.assertEquals()等?你有没有尝试做mvn清洁测试? – khmarbaise 2011-02-17 11:10:22

+0

是的,我已经完成了它们。事实上,我所描述的是完全隔离问题之后。 – 2011-02-17 11:27:27

回答

2

刚刚创建与您的POM文件简单的示例项目(修正了一些部件)并把它放在github ......用Maven 2.2.1和Maven 3.0.2测试完美。该问题的原因一定在别处......

0

请注明万无一失的插件版本(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> 
相关问题