Mvn 构建成功但未执行任何测试

Mvn build success but no tests are executed

我几乎不知道为什么会这样,但是当我 运行

mvn clean install

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

一切正常,直到我对我的 pom.xml 文件做了一个小改动,所以它可以包含依赖项 类 我在我的代码中使用而不是从字面上导入几个 类进入我的项目。

这是我在 运行 maven:

时得到的 terminal/console 输出
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 构建或 运行 我的测试?会不会是我新增的依赖?

只是为了指出。确保您的测试 classes 在测试文件夹(包)中,并且 class 名称应该是 Test*、*Test、*TestCase。

Surefire 有一种机制来判断是 运行 JUnit 还是 TestNG。可能您的 dependencies/code 中的某些内容正在确保一定要尝试使用 TestNG。

您可以禁用自动检测并强制测试提供商(请参阅文档中的 selecting providers)。仅供参考,您需要按以下方式配置surefire(取自之前的link)。这将强制 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 插件。