【发布时间】:2021-10-26 01:09:45
【问题描述】:
我对 Java/Maven 比较陌生,并尝试从命令行运行 Maven 项目 TestNG 套件。它构建但不运行测试。它们在 Eclipse 中工作正常。
[INFO] Scanning for projects...
[INFO]
[INFO] -------------< com.agricorp:AutomationResourcesFramework >--------------
[INFO] Building FBRAutomationTestSuite 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ AutomationResourcesFramework ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\TFS\TS JAVA Automation\Development\FBRAutomationTestSuite\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ AutomationResourcesFramework ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ AutomationResourcesFramework ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\TFS\TS JAVA Automation\Development\FBRAutomationTestSuite\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ AutomationResourcesFramework ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 23 source files to C:\TFS\TS JAVA Automation\Development\FBRAutomationTestSuite\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ AutomationResourcesFramework ---
[INFO] Surefire report directory: C:\TFS\TS JAVA Automation\Development\FBRAutomationTestSuite\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@47d384ee
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.611 sec
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.055 s
[INFO] Finished at: 2021-08-25T18:00:46-04:00
[INFO] ------------------------------------------------------------------------
我在下面添加了项目设置。将testng.xml 重命名为FBRAutomationTestSuite.xml。
我做错了什么?
添加了完整的pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.agricorp</groupId>
<artifactId>FBRAutomationTestSuite</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>FBRAutomationTestSuite</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!--framework.jar.path>C:/Users/nram/.m2/repository/com/agricorp/AutomationResourcesFramework/1.0</framework.jar.path-->
<framework.jar.path>C:\TFS\TS JAVA Automation\Development</framework.jar.path>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.8.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.14.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.4.0</version>
<!--scope>test</scope-->
</dependency>
<!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>5.0.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.codoid.products/fillo -->
<dependency>
<groupId>com.codoid.products</groupId>
<artifactId>fillo</artifactId>
<version>1.21</version>
</dependency>
<dependency>
<groupId>com.agricorp</groupId>
<artifactId>AutomationResourcesFrameworks</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${framework.jar.path}/AutomationResourcesFramework.jar</systemPath>
</dependency>
</dependencies>
<profiles>
<profile>
<id>SanityTests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>RegressionTests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>FBRAutomationTestSuite.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
【问题讨论】:
-
你能发布你的 pom.xml 吗?
-
请注意,Java 约定说包名应该全小写。此外,运行
mvn -X test(您将获得非常详细的输出)并查看 Maven 正在寻找什么作为入口点;我对 TestNG 不太熟悉,但我知道对于 JUnit,默认情况下它会查找名称以Test结尾的类。 -
这可能是个人喜好,但我不会在 Maven 中使用在其 Welcome page 上只有一个
ant示例的框架,其中还包含两个指向博客的 404 链接,应该解释原因用于创建 TestNG,并且由于 JUnit 5 已经推出 5 年,因此在其迁移页面上指的是 JUnit 4。 -
续:... 其中Maven Surefire page 提到“不支持的 TestNG 版本 - TestNG 5.14.3:格式错误的 pom.xml。 - TestNG 5.14.4 和 5.14。 5:TestNG 正在使用缺少的依赖项(org.testng:guice:2.0)。排除它,可能会破坏某些功能。"
-
在上面添加了完整的 pom.xml 文件。