Search code examples
eclipsetestngtestng-eclipse

Run As TestNG is not shown for class extending AbstractTestNGCucumberTests


enter image description herePlease note that I've searched for this particular question & found couple of them but none of them had scenario related to cucumber integration.

I've a test runner class extending AbstractTestNGCucumberTests.

I've also installed Eclipse TestNG plugin as well 6.12

Also adding entry under TestNG under Run Configuration, didn't help to solve the issue.

Mac + Eclipse 4.7.0

@CucumberOptions(features={"src/test/resources/WunderlistAndroid.feature"}, strict = false, format = { "pretty","json:target/cucumber.json" }, tags = { "~@ignore" })
    public class WLSignIn extends AbstractTestNGCucumberTests{
    @BeforeClass
        public void launchAppiumServer(){
           //code doing desired action
        }

    @AfterClass
        public void killAppiumServer(){
         //code doing desired action
    }

}

Solution

  • The problem is due to the fact that the eclipse TestNG plugin doesn't see any @Test methods in your class. I believe the plugin is contextual in nature and hence shows the Run As > TestNG Test only when it sees atleast one @Test method in your test class. Since the @Test method resides in your base class, the plugin doesnt see that and hence you don't see it.

    To get past this, you can perhaps add a dummy test method such as the one below and that should bring back the Run as > TestNG test option.

    @Test(enabled=false)
    public void dummyTestMethod() {}
    

    On a side note: You might want to file this as an issue in the TestNG project and see if its worth getting fixed.

    Details that can be used for the bug :

    If the base class resides within a jar (and has one or more @Test annotated test methods) then the eclipse testng plugin doesn't see the child class (WLSignIn) the first time. But after one adds a disabled @Test method to the child class (WLSignIn) the option shows up. This happens irrespective of whether the child class extends from another class in the same project or from another class which resides in a jar (in your case cucumber.api.testng.AbstractTestNGCucumberTests)