'import org.testng.annotations.*; Can not be resolved

I have successfully installed TestNG and confirmed in eclipse (4.9.0) as well. But while creating a basic class without main class i am getting error at the annotation @Test. Even after importing the test annotations package and the error is present on package as well. and error states it can not be resolved. enter image description here



Solution 1:[1]

In eclipse you need to add testng library to your project after installation. Right click on project --> build path --> Add Libraries --> TestNG library, then it will work

Solution 2:[2]

Remove the module-info.java class from the project and try again.

Solution 3:[3]

If you are using maven project change scope test and add scope compile-

<!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId> testng </artifactId>
            <version>6.14.3</version>
            <scope>compile</scope>  //replace test to compile 
        </dependency>

Solution 4:[4]

Download TestNg jar and add it to build path. It will resolve your issue.

Url: https://mvnrepository.com/artifact/org.testng/testng

Solution 5:[5]

change JavaSE version to JavaSE-1.8

Solution 6:[6]

Changing JavaSE version to JavaSE-1.8 works

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 murali selenium
Solution 2 dumitru popa
Solution 3 Sazib
Solution 4 Being Automation
Solution 5 Vignesh S
Solution 6 Surya Kumar