【发布时间】:2022-01-07 01:15:48
【问题描述】:
我有一个问题我已经好几天没能解决了(我已经通过了所有的谷歌)
我尝试通过 CMD 运行我的整个项目 (TestNG) 测试。
当我使用mvn -X package 运行项目时,它会运行整个项目。
当我对我的 TestNG.xml 文件进行更改时,问题就开始了,因此它只运行一些测试。所以相同的命令 (mvn -X package) 不起作用,它会继续运行所有测试。
当我尝试使用来自 Internet 的命令将项目作为 TestNG 运行时
java org.testng.TestNG TestNG.xml(我发现的所有变化)
它总是向我显示相同的错误消息“错误:无法找到或加载主类 org.testng.TestNG”
我看到他们多次使用我没有的 LIB 和 BIN 文件夹,我只有 SRC(我通过 intellij 工作),我不知道需要放置什么或如何创建这些文件夹。
附言 我注意到很多人都遇到过这个问题,但是没有答案可以帮助我
pom.xml ` 4.0.0
<groupId>SimplyClub.Tests.SubTotalTest</groupId>
<artifactId>SimplyTest</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>4.4.3</version>
<scope>test</scope>
</dependency>
<!-- 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/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>simplyclub.test.infrastructur</groupId>
<artifactId>SimplyClub</artifactId>
<scope>system</scope>
<version>1.0-SNAPSHOT</version>
<systemPath>${user.home}/IdeaProjects/SimplyTestInfrastructure/out/artifacts/SimplyTestInfrastructure_jar/SimplyTestInfrastructure.jar</systemPath>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>5.0.8</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>
</dependencies>
<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>
</properties>
<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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<!--<source>1.8</source>-->
<!--<target>1.8</target>-->
</configuration>
</plugin>
</plugins>
</build>
`
TestNG.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
<suite name="SimplyTest">
<listeners>
<listener class-name = "utilities.Listeners"></listener>
</listeners>
<test name="Sub Total">
<classes>
<class name="Tests.SubTotalTest"></class>
</classes>
</test>
<test name="TranEnd">
<classes>
<class name="Tests.TranEndTest"></class>
</classes>
</test>
更新:
这是我运行命令mvn package 后出现的内容
没有错误
更新2:
所以在安装完所有插件之后,就有了进展
但现在它给我带来了另一个我无法理解的错误
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler- 在此输入代码plugin:3.1:testCompile
我还更新了 POM.xml
【问题讨论】:
-
“所以同样的命令(mvn -X package)不起作用”。 “不起作用”是什么意思?
-
删除
<version>RELEASE</version>并用正确的版本号替换它...进一步删除<scope>Tests.SubTotalTest</scope>并用<scope>test</scope>替换它...也在另一个依赖项中删除<scope>Tests.SubTotalTest</scope>... . 完全错了... -
请通过
mvn package在普通命令行上检查您的构建,应该已经警告可能有错误.. -
@tgdavies 命令,它不会运行它在那里注册的测试,它会运行项目中的所有测试
-
@khmarbaise 我做了你记录的更改,没有解决问题