'How to Run as a TestNG test file

When I right-click the class file and choose "Run As" TestNG isn't an option.

I've added the TestNG jars by adding the dependency in the pom.xml and running as a Maven install. When I right-click my project and choose Properties -> Java Build Path -> Add Library, TestNG doesn't show up in the list. This is an existing project and I see JUnit as well as a few others not pertaining to testing. Am I missing something to get this added? I'm able to import and use items from the TestNG API.



Solution 1:[1]

When I was running it to begin with, I only had a class with a @BeforeTest annotation and Eclipse wasn't seeing it as a Test Case. As soon as I added @Test to the next class for the first.

So the answer is to make sure there's a actual @Test test case class in the class file.

Solution 2:[2]

You have to install testng in eclipse

Can install by searching in Eclipse Marketplace or install as new software . For more details https://testng.org/doc/eclipse.html

Solution 3:[3]

Please ensure if there are test cases under @Test annotations and check if that test annotation is imported from 'org.testng.annotations.Test' and not related to Junit.

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 WeVie
Solution 2 murali selenium
Solution 3 Ayush Goel