Java Maven测试失败:找不到符号
我正在尝试使用Maven设置测试。尝试运行命令mvn测试时出现以下错误:Java Maven测试失败:找不到符号,java,maven,selenium,testng,Java,Maven,Selenium,Testng,我正在尝试使用Maven设置测试。尝试运行命令mvn测试时出现以下错误: [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] /Users/dso/Documents/Eclipse-Workspace/MavenSample/src/test/java/MavenSample/MavenSample/RestAPITest.java:[
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/dso/Documents/Eclipse-Workspace/MavenSample/src/test/java/MavenSample/MavenSample/RestAPITest.java:[3,30] cannot find symbol
symbol: class Test
location: package org.testng.annotations
mvn clean和mvn compile对我来说都很好,没有错误。此外,如果测试只是作为testng运行,那么测试本身运行良好。mvn测试完成后,测试失败。下面是我的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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MavenSample</groupId>
<artifactId>MavenSample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MavenSample</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<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/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.0.0-beta4</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
您的问题是编译时需要该库,而您只指定了测试范围 尝试更改此选项:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>compile</scope>
</dependency>
[更新]在您使用的beta版中,org.testng.annotations包中没有测试注释。您的问题是编译时需要该库,而您只指定了测试范围 尝试更改此选项:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>compile</scope>
</dependency>
[更新]在您使用的beta版中,org.testng.annotations包中没有测试注释。非常感谢!经过一周的努力,花了几个小时寻找答案,我终于解决了这个问题。我遇到的问题与问题中提到的完全相同。修复程序正在更改xml依赖关系。以前是这样的:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.0.0-beta4</version>
</dependency>
我将XML更改为:--->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>compile</scope>
</dependency>
非常感谢你!经过一周的努力,花了几个小时寻找答案,我终于解决了这个问题。我遇到的问题与问题中提到的完全相同。修复程序正在更改xml依赖关系。以前是这样的:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.0.0-beta4</version>
</dependency>
我将XML更改为:--->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>compile</scope>
</dependency>
可能您的类RestAPITest有编译错误。你能给我们展示这个类吗?你能移除junit依赖项吗。只保留testNG?测试中没有正确的代码。它只是一个示例文件:包MavenSample.MavenSample;导入org.testng.annotations.Test;公共类RestAPITest{@Test public void PostJIRA{System.out.printlnPostJIRA;}@Test public void DeleteTwitter{System.out.printlndeteTwitter;}}@MyChellTexiRasTill得到相同的错误@qingfeiyuan可能您的类RestAPITest有编译错误。你能给我们展示这个类吗?你能移除junit依赖项吗。只保留testNG?测试中没有正确的代码。它只是一个示例文件:包MavenSample.MavenSample;导入org.testng.annotations.Test;公共类RestAPITest{@Test public void PostJIRA{System.out.printlnPostJIRA;}@Test public void DeleteTwitter{System.out.printlndeteTwitter;}}@Mychelltexeirastill得到同样的错误@QingfeiYuan