英文:
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] --------------------< MavenTestDemo:MavenTestDemo >---------------------
[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>
<?xml version="1.0" encoding="UTF-8"?>
<suite name="maven test">
<test name="TestNG testing">
<packages>
<package name="com.qa.tests.*"/>
</packages>
</test>
</suite>
POM.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MavenTestDemo</groupId>
<artifactId>MavenTestDemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<suiteXMLFiles>
<classpathScope>test</classpathScope>
<suiteXMLFile>src/test/resources/TestNG.xml</suiteXMLFile>
</suiteXMLFiles>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>3.0.0-M4</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
</dependencies>
</project>
英文:
<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] --------------------< MavenTestDemo:MavenTestDemo >---------------------
[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>
<?xml version="1.0" encoding="UTF-8"?>
<suite name="maven test">
<test name="TestNG testing">
<packages>
<package name="com.qa.tests.*"/>
</packages>
</test>
</suite>
POM.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MavenTestDemo</groupId>
<artifactId>MavenTestDemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<suiteXMLFiles>
<classpathScope>test</classpathScope>
<suiteXMLFile>src/test/resources/TestNG.xml</suiteXMLFile>
</suiteXMLFiles>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>3.0.0-M4</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
</dependencies>
</project>
Can you please provide me insight on these.
答案1
得分: 0
我看不到Maven编译插件。
I don't see Maven compiler plugin.
英文:
<!-- Compiler plugin configures the java version to be usedfor compiling the code -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
专注分享java语言的经验与见解,让所有开发者获益!
评论