Why does TestNG execute an open method without the @Test annotation

I have 5 tests with @Test annotation in one class (I use Java and TestNG) and one public helper method (in the same class) that has some logic, and each testing method calls this method. The problem is that all 5 tests pass, but testng tries to execute a helper method and shows that the run is running as a pass / fail. The following is the code I'm using:

public class TestClass extends BaseTestClass {

@Test
public void testA(){
    //first test code 
}

@Test
public void testB(){
    //second test code
}

@Test
public void testC(){
    //third test code
}

@Test
public void testD(){
    //fourth test code
}

@Test
public void testE(){
    //fifth test code
}


public void helperMethod( ){
    //some logic that each test method is using
}  

}

Here is the result of m:

PASSED: testA
PASSED: testB
PASSED: testC
PASSED: testD
PASSED: testE
SKIPPED: helperMethod
org.testng.TestNGException: 
Method helperMethod requires 2 parameters but 0 were supplied in the @Test annotation.
    at org.testng.internal.Parameters.checkParameterTypes(Parameters.java:198)
    at org.testng.internal.Parameters.createParameters(Parameters.java:134)
    at org.testng.internal.Parameters.createParameters(Parameters.java:373)
    at org.testng.internal.Parameters.handleParameters(Parameters.java:450)
    at org.testng.internal.Invoker.handleParameters(Invoker.java:1383)
    at org.testng.internal.Invoker.createParameters(Invoker.java:1075)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1180)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)


===============================================
    Default test
    Tests run: 6, Failures: 0, Skips: 1
===============================================

However, if I declare helperMethod as private, it works fine. Can someone explain why this is happening?

+4
source share
1 answer

TestClass @Test? ​​, .

+10

All Articles