Reputation: 2693
I am trying to set up tests using Maven. I am getting the following error while trying to run the command "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
Both mvn clean and mvn compile works fine for me with no errors. Also the test itself runs fine if it is ran as just testng. The test fails when mvn test is done. Below is the code for my pom.xml file.
<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>
Upvotes: 2
Views: 9631
Reputation: 11
Thank You So Much! After struggling a week with spending hours searching for the answer finally i was able to resolve the issue. I was having the same exact problem as mentioned in the questions. The fix was changing the xml dependency. Previously it was like this:-
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.0.0-beta4</version>
</dependency>
I changed the XML to This:----->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>compile</scope>
</dependency>
Upvotes: 1
Reputation: 2220
Your problem is that the library is needed in compilation time, and you only specified to "test" scope.
Try to change this:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>compile</scope>
</dependency>
[UPDATED] in the beta version you are using, there is no Test annotation in the package "org.testng.annotations".
Upvotes: 6