Maven 测试失败:找不到符号

我正在尝试使用 Maven 设置测试。尝试运行命令“mvn test”时出现以下错误:


[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>




达令说
浏览 227回答 2
2回答

一只名叫tom的猫

您的问题是编译时需要该库,而您只指定了“测试”范围。尝试改变这个:<dependency>&nbsp; &nbsp;<groupId>org.testng</groupId>&nbsp; &nbsp;<artifactId>testng</artifactId>&nbsp; &nbsp;<version>6.14.3</version>&nbsp; &nbsp;<scope>compile</scope></dependency>[更新] 在您使用的测试版中,包“org.testng.annotations”中没有测试注释。

炎炎设计

太感谢了!经过一个星期的努力,花了几个小时寻找答案,终于我能够解决这个问题。我遇到了与问题中提到的完全相同的问题。修复是更改 xml 依赖项。以前是这样的:-<dependency>&nbsp; &nbsp; <groupId>org.testng</groupId>&nbsp; &nbsp; <artifactId>testng</artifactId>&nbsp; &nbsp; <version>7.0.0-beta4</version></dependency>我将 XML 更改为:-----><dependency>&nbsp; &nbsp; <groupId>org.testng</groupId>&nbsp; &nbsp; <artifactId>testng</artifactId>&nbsp; &nbsp; <version>6.14.3</version>&nbsp; &nbsp; <scope>compile</scope></dependency>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java