【问题标题】:maven does not print name of tested class; replaces class name with TestSuitemaven 不打印测试类的名称;用 TestSuite 替换类名
【发布时间】:2017-12-07 11:35:21
【问题描述】:

我正在用 testNG 运行这个项目,我得到的测试结果(成功的)为

[RemoteTestNG] detected TestNG version 6.13.1
Success!!
Dec 07, 2017 4:44:06 PM org.openqa.selenium.remote.ProtocolHandshake 
createSession
INFO: Detected dialect: OSS
PASSED: begin
PASSED: google

===============================================
    Default test
    Tests run: 2, Failures: 0, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 2, Failures: 0, Skips: 0
===============================================

但是当作为 Maven 测试运行时,它不会打印通过的测试用例(或任何测试)的名称。它只是给出了运行测试的数量。我希望通过的案例也打印在这里。

附: - 类在 src/test/java 中。尝试按照问题之一中的建议将其更改为 src/main/java。但是 maven 以这种方式完全跳过了测试,因为 Surefire-plugin 运行了测试源目录 src/test/java 中的所有测试。

[INFO] Scanning for projects...
[INFO]                                                                         

[INFO] ------------------------------------------------------------------------
[INFO] Building MavenFrstProj 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenFrstProj ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory 
C:\Users\Shrikanth\workspace\MavenFrstProj\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ 
MavenFrstProj ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) 
@ MavenFrstProj ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory 
C:\Users\Shrikanth\workspace\MavenFrstProj\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ 
MavenFrstProj ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.20:test (default-test) @ MavenFrstProj --
-
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running TestSuite
Success!!
Dec 07, 2017 4:45:58 PM org.openqa.selenium.remote.ProtocolHandshake 
createSession
INFO: Detected dialect: OSS
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 8.017 
s - in TestSuite
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] ---------------------------------------------------------------------
---
[INFO] BUILD SUCCESS
[INFO] ---------------------------------------------------------------------
---
[INFO] Total time: 11.972 s
[INFO] Finished at: 2017-12-07T16:46:02+05:30
[INFO] Final Memory: 12M/178M
[INFO] ------------------------------------------------------------------------

注意:同时检查在 target/surefire-reports 中生成的 xml 报告(TestSuite),它将类名替换为 TestSuite,并且在控制台输出中它打印 Running TestSuite 而不是 Running classname>。可能是根,但不确定。我如何解决它。请帮忙!

【问题讨论】:

  • 你为什么使用TestSuites...

标签: eclipse maven automated-tests testng


【解决方案1】:

默认情况下,Surefire 插件会自动包含所有具有以下通配符模式的测试类:

"**/Test*.java" - includes all of its subdirectories and all Java filenames that start with "Test".
"**/*Test.java" - includes all of its subdirectories and all Java filenames that end with "Test".
"**/*Tests.java" - includes all of its subdirectories and all Java filenames that end with "Tests".
"**/*TestCase.java" - includes all of its subdirectories and all Java filenames that end with "TestCase".

确保你的测试类名遵循这个模式,否则,在 pom.xml 中包含每个类

【讨论】:

  • 将类名更改为 Test*,在 pom.xml 中添加了类路径。但仍然没有任何反应。
猜你喜欢
  • 2013-07-14
  • 2015-09-18
  • 1970-01-01
  • 1970-01-01
  • 2011-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多