Mvn构建成功但没有执行测试

时间:2015-08-05 21:15:10

标签: java maven pom.xml cobertura

我几乎不知道为什么会这样,但是当我跑步时

mvn clean install

#Builds with class instrumentation (code coverage)
mvn cobertura:cobertura

一切正常,直到我对我的pom.xml文件进行了一些细微的更改,因此它可能包含我在代码中使用的依赖类,而不是将几个类直接导入到我的项目中。

这是我运行maven时得到的终端/控制台:

SDGL12025ba66:TestCompletenessCompilerRuntime mosawi$ mvn cobertura:cobertura
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building TestCompletenessCompilerRuntime 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> cobertura-maven-plugin:2.7:cobertura (default-cli) > [cobertura]test @ TestCompletenessCompilerRuntime >>>
Downloading: http://ctg-cache-repo.corp.generalatomics.net/nexus/content/repositories/public/org/slf4j/slf4j-log4j12/1.6.2/slf4j-log4j12-1.6.2.pom
Downloaded: http://ctg-cache-repo.corp.generalatomics.net/nexus/content/repositories/public/org/slf4j/slf4j-log4j12/1.6.2/slf4j-log4j12-1.6.2.pom (2 KB at 14.2 KB/sec)
Downloading: http://ctg-cache-repo.corp.generalatomics.net/nexus/content/groups/public/com/generalatomics/ctg/tla/models/model-data-source/2015.1.11-SNAPSHOT/maven-metadata.xml
Downloaded: http://ctg-cache-repo.corp.generalatomics.net/nexus/content/groups/public/com/generalatomics/ctg/tla/models/model-data-source/2015.1.11-SNAPSHOT/maven-metadata.xml (804 B at 3.1 KB/sec)
Downloading: http://ctg-cache-repo.corp.generalatomics.net/nexus/content/groups/public/com/generalatomics/ctg/tla/compilers/decision-map-common/2015.1.11-SNAPSHOT/maven-metadata.xml
Downloaded: http://ctg-cache-repo.corp.generalatomics.net/nexus/content/groups/public/com/generalatomics/ctg/tla/compilers/decision-map-common/2015.1.11-SNAPSHOT/maven-metadata.xml (809 B at 3.6 KB/sec)
Downloading: http://ctg-cache-repo.corp.generalatomics.net/nexus/content/groups/public/com/generalatomics/ctg/tla/models/decision-table-model/2015.1.11-SNAPSHOT/maven-metadata.xml
Downloaded: http://ctg-cache-repo.corp.generalatomics.net/nexus/content/groups/public/com/generalatomics/ctg/tla/models/decision-table-model/2015.1.11-SNAPSHOT/maven-metadata.xml (807 B at 1.2 KB/sec)
Downloading: http://ctg-cache-repo.corp.generalatomics.net/nexus/content/groups/public/com/generalatomics/ctg/tla/compilers/mapping-maven-plugin/2015.1.11-SNAPSHOT/maven-metadata.xml
Downloaded: http://ctg-cache-repo.corp.generalatomics.net/nexus/content/groups/public/com/generalatomics/ctg/tla/compilers/mapping-maven-plugin/2015.1.11-SNAPSHOT/maven-metadata.xml (810 B at 3.7 KB/sec)
Downloading: http://ctg-cache-repo.corp.generalatomics.net/nexus/content/groups/public/com/generalatomics/ctg/tla/models/calc-graph-model/2015.1.11-SNAPSHOT/maven-metadata.xml
Downloaded: http://ctg-cache-repo.corp.generalatomics.net/nexus/content/groups/public/com/generalatomics/ctg/tla/models/calc-graph-model/2015.1.11-SNAPSHOT/maven-metadata.xml (803 B at 2.1 KB/sec)
Downloading: http://ctg-cache-repo.corp.generalatomics.net/nexus/content/repositories/public/org/slf4j/slf4j-log4j12/1.6.2/slf4j-log4j12-1.6.2.jar
Downloaded: http://ctg-cache-repo.corp.generalatomics.net/nexus/content/repositories/public/org/slf4j/slf4j-log4j12/1.6.2/slf4j-log4j12-1.6.2.jar (10 KB at 380.9 KB/sec)
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ TestCompletenessCompilerRuntime ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 3 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:compile (default-compile) @ TestCompletenessCompilerRuntime ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- cobertura-maven-plugin:2.7:instrument (default-cli) @ TestCompletenessCompilerRuntime ---
[INFO] Cobertura 2.1.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
[INFO] Cobertura: Loaded information on 13 classes.
[INFO] Cobertura: Saved information on 13 classes.
[INFO] Cobertura: Saved information on 13 classes.

[ERROR] SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/mosawi/.m2/repository/ch/qos/logback/logback-classic/1.0.13/logback-classic-1.0.13.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/mosawi/.m2/repository/org/slf4j/slf4j-log4j12/1.6.2/slf4j-log4j12-1.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]

[INFO] Instrumentation was successful.
[INFO] NOT adding cobertura ser file to attached artifacts list.
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ TestCompletenessCompilerRuntime ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 832 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.3:testCompile (default-testCompile) @ TestCompletenessCompilerRuntime ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 7 source files to /Users/mosawi/Perforce/mosawi_newTPS/QE/automation/TestCompletenessCompilerRuntime/target/test-classes
[INFO] /Users/mosawi/Perforce/mosawi_newTPS/QE/automation/TestCompletenessCompilerRuntime/src/test/java/com/generalatomics/ctg/tla/compilers/CompilerTest.java: /Users/mosawi/Perforce/mosawi_newTPS/QE/automation/TestCompletenessCompilerRuntime/src/test/java/com/generalatomics/ctg/tla/compilers/CompilerTest.java uses or overrides a deprecated API.
[INFO] /Users/mosawi/Perforce/mosawi_newTPS/QE/automation/TestCompletenessCompilerRuntime/src/test/java/com/generalatomics/ctg/tla/compilers/CompilerTest.java: Recompile with -Xlint:deprecation for details.
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ TestCompletenessCompilerRuntime ---
[INFO] Surefire report directory: /Users/mosawi/Perforce/mosawi_newTPS/QE/automation/TestCompletenessCompilerRuntime/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@7c40bc88
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.32 sec

Results :

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

[INFO] 
[INFO] <<< cobertura-maven-plugin:2.7:cobertura (default-cli) < [cobertura]test @ TestCompletenessCompilerRuntime <<<
[INFO] 
[INFO] --- cobertura-maven-plugin:2.7:cobertura (default-cli) @ TestCompletenessCompilerRuntime ---
[INFO] Cobertura 2.1.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
[INFO] Cobertura: Loaded information on 13 classes.
Report time: 249ms

[INFO] Cobertura Report generation was successful.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.421 s
[INFO] Finished at: 2015-08-05T14:06:28-07:00
[INFO] Final Memory: 28M/438M
[INFO] ------------------------------------------------------------------------
SDGL12025ba66:TestCompletenessCompilerRuntime mosawi$ 

我真的不明白可能导致这种情况的原因是什么?任何帮助将非常感激。感谢

你看到slf4j的错误应该没问题。之前我已经看过了,所以我确信这不是这里发生的事情的罪魁祸首

修改 我注意到我的测试似乎正在使用TestNG执行但我使用的是JUnit:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@7c40bc88
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.32 sec

为什么mvn clean install会尝试使用TestNG而不是Junit构建或运行我的测试?它可能是我添加的新依赖项吗?

2 个答案:

答案 0 :(得分:1)

要点。确保您的测试类位于测试文件夹(包)中,类名应为Test *,* Test,* TestCase。

答案 1 :(得分:1)

Surefire有一种机制来确定是运行JUnit还是TestNG。您的依赖项/代码中的某些东西可能会确保尝试使用TestNG。

您可以禁用自动检测并强制测试提供程序(请参阅文档中的selecting providers)。仅供将来参考,您需要以下列方式配置surefire(取自上一个链接)。这将迫使Surefire使用Junit 4.7兼容的提供商。

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18.1</version>
    <dependencies>
      <dependency>
        <groupId>org.apache.maven.surefire</groupId>
        <artifactId>surefire-junit47</artifactId>
        <version>2.18.1</version>
      </dependency>
    </dependencies>
  </plugin>

我曾经见过这个问题,大约6到7年前,我不记得我做了什么来解决它让Surefire正确检测到测试提供程序,但我确实记得重新插入了surefire插件。 / p>