TestNG.XML在通过maven运行时不执行,即使在POM.XML中进行了正确的配置。

huangapple 未分类评论45阅读模式
英文:

TestNG.XML not executing.when run via maven -mvn test - even after proper configurations in POM.XML

问题

<br>
这是我在StackOverflow上的第一个问题,所以如果问题不准确,请原谅。
<br>
我创建了一个Maven项目,尝试通过Maven运行TestNG.XML,但未能成功。以下是输出内容:

[INFO] 正在扫描项目...
[INFO]
[INFO] --------------------&lt; MavenTestDemo:MavenTestDemo &gt;---------------------
[INFO] 构建 MavenTestDemo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenTestDemo ---
[WARNING] 使用平台编码(实际上是Cp1252)复制过滤后的资源,即构建依赖于平台!
[INFO] 复制 0 个资源
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenTestDemo ---
[INFO] 没有要编译的内容 - 所有类都是最新的
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ MavenTestDemo ---
[WARNING] 使用平台编码(实际上是Cp1252)复制过滤后的资源,即构建依赖于平台!
[INFO] 复制 1 个资源
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ MavenTestDemo ---
[INFO] 检测到更改 - 重新编译模块!
[WARNING] 文件编码尚未设置,使用平台编码Cp1252,即构建依赖于平台!
[INFO] 编译 3 个源文件到 C:\Users\sneha\eclipse-workspace\MavenTestDemo\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M4:test (default-test) @ MavenTestDemo ---
[INFO] ---------------------------------------------------------------------
[INFO] 构建成功
[INFO] ---------------------------------------------------------------------
[INFO] 总时间:  3.458 秒
[INFO] 完成于: 2020-04-07T18:26:56+05:30
[INFO] ---------------------------------------------------------------------

测试用例未执行,仅显示构建成功。但是,当我尝试使用TestNG套件运行TestNG.xml时,可以正常运行。
<br>当我将类名设置为“Demo1Test.java”时,代码按预期运行,但并不总是以Test结尾。

请查看我的TestNG.xml和POM.xml文件如下:

TestNG.xml
<br>

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;suite name=&quot;maven test&quot;&gt;
&lt;test name=&quot;TestNG testing&quot;&gt;
&lt;packages&gt;
&lt;package name=&quot;com.qa.tests.*&quot;/&gt;
&lt;/packages&gt;
&lt;/test&gt;
&lt;/suite&gt;

POM.xml

&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;MavenTestDemo&lt;/groupId&gt;
  &lt;artifactId&gt;MavenTestDemo&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
&lt;build&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
        &lt;version&gt;3.0.0-M4&lt;/version&gt;
       
        &lt;configuration&gt;
        &lt;suiteXMLFiles&gt;
       &lt;classpathScope&gt;test&lt;/classpathScope&gt;
                &lt;suiteXMLFile&gt;src/test/resources/TestNG.xml&lt;/suiteXMLFile&gt;
                &lt;/suiteXMLFiles&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;  
&lt;dependencies&gt;
&lt;dependency&gt;
  &lt;groupId&gt;org.apache.maven.surefire&lt;/groupId&gt;
  &lt;artifactId&gt;surefire-testng&lt;/artifactId&gt;
  &lt;version&gt;3.0.0-M4&lt;/version&gt;
&lt;/dependency&gt;
  &lt;dependency&gt;
  &lt;groupId&gt;org.testng&lt;/groupId&gt;
  &lt;artifactId&gt;testng&lt;/artifactId&gt;
  &lt;version&gt;6.8&lt;/version&gt;
  &lt;scope&gt;test&lt;/scope&gt;
  
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
  &lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt;
        &lt;artifactId&gt;selenium-java&lt;/artifactId&gt;
        &lt;version&gt;3.141.59&lt;/version&gt;
  &lt;/dependency&gt;
 
  &lt;/dependencies&gt;
  
&lt;/project&gt;
英文:

<br>
This is my first question in StackOverflow, so please forgive if the question is not accurate.
<br>
I created a maven project. Trying to run TestNG.XML through maven but the same is not working. Getting below output

[INFO] Scanning for projects...
[INFO]
[INFO] --------------------&lt; MavenTestDemo:MavenTestDemo &gt;---------------------
[INFO] Building MavenTestDemo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenTestDemo ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ MavenTestDemo ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ MavenTestDemo ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ MavenTestDemo ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 3 source files to C:\Users\sneha\eclipse-workspace\MavenTestDemo\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M4:test (default-test) @ MavenTestDemo ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.458 s
[INFO] Finished at: 2020-04-07T18:26:56+05:30
[INFO] ------------------------------------------------------------------------

The test cases are not executing just showing Build success. But when I try to run TestNG.xml with TestNG suite, the same is running properly.
<br>When I give class name as "Demo1Test.java" then code runs as expected but always we can't give name ending with Test.

Please find my TestNG.xml and POM.xml files below:

TestNG.xml
<br>

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;suite name=&quot;maven test&quot;&gt;
&lt;test name=&quot;TestNG testing&quot;&gt;
&lt;packages&gt;
&lt;package name=&quot;com.qa.tests.*&quot;/&gt;
&lt;/packages&gt;
&lt;/test&gt;
&lt;/suite&gt;

POM.xml

&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;MavenTestDemo&lt;/groupId&gt;
  &lt;artifactId&gt;MavenTestDemo&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
&lt;build&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
        &lt;version&gt;3.0.0-M4&lt;/version&gt;
       
        &lt;configuration&gt;
        &lt;suiteXMLFiles&gt;
       &lt;classpathScope&gt;test&lt;/classpathScope&gt;
                &lt;suiteXMLFile&gt;src/test/resources/TestNG.xml&lt;/suiteXMLFile&gt;
                &lt;/suiteXMLFiles&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;  
&lt;dependencies&gt;
&lt;dependency&gt;
  &lt;groupId&gt;org.apache.maven.surefire&lt;/groupId&gt;
  &lt;artifactId&gt;surefire-testng&lt;/artifactId&gt;
  &lt;version&gt;3.0.0-M4&lt;/version&gt;
&lt;/dependency&gt;
  &lt;dependency&gt;
  &lt;groupId&gt;org.testng&lt;/groupId&gt;
  &lt;artifactId&gt;testng&lt;/artifactId&gt;
  &lt;version&gt;6.8&lt;/version&gt;
  &lt;scope&gt;test&lt;/scope&gt;
  
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
  &lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt;
        &lt;artifactId&gt;selenium-java&lt;/artifactId&gt;
        &lt;version&gt;3.141.59&lt;/version&gt;
  &lt;/dependency&gt;
 
  &lt;/dependencies&gt;
  
&lt;/project&gt;

Can you please provide me insight on these.

答案1

得分: 0

我看不到Maven编译插件。

maven-compiler-plugin
1.6
1.6

英文:

I don't see Maven compiler plugin.

   &lt;!-- Compiler plugin configures the java version to be usedfor compiling the code --&gt; 

&lt;plugin&gt; 
    &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt; 
    &lt;configuration&gt; 
    &lt;source&gt;1.6&lt;/source&gt; 
    &lt;target&gt;1.6&lt;/target&gt;
    &lt;/configuration&gt; 
    &lt;/plugin&gt;

huangapple
  • 本文由 发表于 2020年4月7日 21:28:29
  • 转载请务必保留本文链接:https://java.coder-hub.com/61081149.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定