[英]Want to run a maven project with TestNg packages but getting error when executing the project
I have started to configure a maven project for selenium java and excluded the following junit dependency from pom.xml as I want to make it with TestNG. 所以包括 testng 依赖而不是它。
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MobilePackage</groupId>
<artifactId>MobileProject</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>MobileProject</name>
<url>http://maven.apache.org</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>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0-alpha-5</version>
</dependency>
</dependencies>
</project>
编译项目(mvn已编译)并且BUILD成功但当时发生问题,执行项目时($ mvn test)。终端显示以下错误。
[ERROR] /home/PC1/Documents/OfficeProject/MobileProject/src/test/java/MobilePackage/AppTest.java:[3,23] package junit.framework does not exist
[ERROR] /home/PC1/Documents/OfficeProject/MobileProject/src/test/java/MobilePackage/AppTest.java:[4,23] package junit.framework does not exist
.
.
.
[ERROR] /home/PC1/Documents/OfficeProject/MobileProject/src/test/java/MobilePackage/AppTest.java:[11,13] cannot find symbol
[ERROR] symbol: class TestCase
[ERROR] /home/PC1/Documents/OfficeProject/MobileProject/src/test/java/MobilePackage/AppTest.java:[26,19] cannot find symbol
[ERROR] symbol: class Test
[ERROR] location: class MobilePackage.AppTest
所以我发现问题存在于 AppTest.java 文件中。 那里仍然存在追随者。
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
package MobilePackage;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest
extends TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public AppTest( String testName )
{
super( testName );
}
/**
* @return the suite of tests being tested
*/
public static Test suite()
{
return new TestSuite( AppTest.class );
}
/**
* Rigourous Test :-)
*/
public void testApp()
{
assertTrue( true );
}
}
如何摆脱这个问题。我是否需要为 TestNG 配置 apptest.java(我试过了,但是错误没有消失)。我应该同时包括 testNG 和 Z587FEFE304B8E3505DE8295804Z3 吗? 如果是这样,那么它会在未来产生任何问题吗? 请建议。
尝试在 maven 确保触发插件中添加此配置,以便 testng.xml 可以使用 mvn test 命令运行。
org.apache.maven.plugins maven-surefire-plugin 3.0.0-M4 testng.xml
您不能只是将一个库更改为另一个库,并期望您的代码仍然可以工作。 通过从 pom.xml 中删除 JUnit ,您只需从项目中“关闭”这个库。
但是,在您的 pom 中拥有一个 lib 而在您的代码中没有对该 lib 的任何引用是没有意义的。 就像在您的情况下,您的代码在很多地方都引用了 JUnit 库的类。
您需要做的是仔细检查您的代码在哪里使用了 JUnit 实体,并在可能的情况下将它们更改为 TestNG 类似物。 如果不是,恐怕您将不得不摆脱该代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.