maven不打印测试类的名称;用TestSuite替换类名

时间:2017-12-07 11:35:22

标签: eclipse maven automated-tests testng

我用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测试运行时,它不会打印通过的测试用例(或任何测试)的名称。它只是提供了一些测试运行。我希望也可以在这里打印通过的案例。

P.S。 - 类在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 > 。可能是根,但不确定。我如何解决它。请帮忙!

1 个答案:

答案 0 :(得分:0)

默认情况下,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中包含每个类