【发布时间】:2020-08-08 03:04:17
【问题描述】:
我已经开始为 selenium java 配置一个 maven 项目,并从 pom.xml 中排除了以下 junit 依赖项,因为我想使用 TestNG 来实现。所以包含了 testng 依赖而不是它。
junit 依赖
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
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 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;
AppTest.java 代码如下
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 和 junit 吗?如果是这样,那么它会在未来产生任何问题吗?请提出建议。
【问题讨论】:
标签: java maven selenium junit testng