Maven project using testng dependecy

0 votes

Hi

I’ve a simple “hello world” maven project.    I’ve added the following testing dependency under pom.xml.  My question is why is it still giving me an error on import org.testng.annotations.Test?  Shouldn’t the testng dependency under pom.xml take care of this?

Thanks in advance

package tests;
import org.testng.annotations.Test;

public class NewTest
{
    @Test
    public  void mytest()
    {                
        System.out.println("Hello world");
    }
}
 
<dependencies>        
          <!-- TestNG -->
          <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.3.0</version>
            <scope>test</scope>
        </dependency>
</dependencies>

Nov 25, 2020 in Java by zaraaq
• 270 points
6,211 views

1 answer to this question.

+1 vote

Hello @zaraaq,

First try to replace the scope by compile as:

<dependencies>        
          <!-- TestNG -->
          <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.3.0</version>
            <scope>test</scope>
        </dependency>
</dependencies>

Or try this steps(I used Eclipse)):

  1. Open pom.xml file.
  2. Go to "Dependencies" tab.
  3. Select "testng" package and click on "Properties..."
  4. On opened screen change "Scope" option to "compile" and click "OK" to save it.
  5. Try to build your project again with "compile test" goals.

Hope it works!!!

answered Nov 25, 2020 by Niroj
• 82,880 points
Thanks, that worked.

Related Questions In Java

0 votes
1 answer

How can I create an executable JAR with dependencies using Maven?

<build> <plugins> <plugin> ...READ MORE

answered Apr 26, 2018 in Java by sophia
• 1,400 points
977 views
0 votes
2 answers

How can we add the local JAR files to the Maven Project in Java?

Firstly I would like to give credit ...READ MORE

answered Nov 5, 2018 in Java by Sushmita
• 6,910 points
10,157 views
0 votes
1 answer

how to serially execute selenium maven project?

Hi, @Beigi, Do check you have all the ...READ MORE

answered Oct 27, 2020 in Java by Nisha
417 views
0 votes
2 answers

How do I get the current date and time using Java?

If you require a time stamp in ...READ MORE

answered Aug 23, 2019 in Java by Sirajul
• 59,230 points
2,315 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
12,615 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,571 views
0 votes
2 answers

What is the role of TestNG & JUnit frameworks in Selenium?

TestNG and JUnit are test frameworks . it ...READ MORE

answered Sep 4, 2020 in Selenium by Sri
• 3,190 points
2,484 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
6,629 views
0 votes
1 answer

How can I create an executable JAR with dependencies using Maven?

Hello @kartik, You can use the dependency-plugin to ...READ MORE

answered May 28, 2020 in Java by Niroj
• 82,880 points
5,570 views
0 votes
1 answer

How to add local jar files to a Maven project?

Hello @kartik, You can add local dependencies directly ...READ MORE

answered Jul 28, 2020 in Java by Niroj
• 82,880 points
2,052 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP