这是我在 StackOverflow 中的第一个问题,如果问题不准确,请原谅。
我创建了一个 Maven 项目。尝试通过 maven 运行 TestNG.XML 但同样不起作用。得到低于输出
[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] ------------------------------------------------------------------------
测试用例没有执行,只是显示构建成功。但是当我尝试使用 TestNG 套件运行 TestNG.xml 时,它运行正常。
当我将类名称指定为“Demo1Test.java”时,代码将按预期运行,但我们始终无法指定以 Test 结尾的名称。
请在下面找到我的 TestNG.xml 和 POM.xml 文件:
TestNG.xml
<?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>
您能否向我提供有关这些的见解。
最佳答案
我没有看到 Maven 编译器插件。
<!-- 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 - TestNG.XML 未执行。通过 maven -mvn test 运行时 - 即使在 POM.XML 中进行了正确配置后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61081149/