I have 5 tests with @Test annotation in single class (I am using java and TestNG) and one public helper method (in same class) that has some logic and each test method is calling this method. Problem is that, all the 5 tests are passing but testng is trying to execute the helper method and showing that run as a skip/failure. Following is the code that I am 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 m getting:
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 the helperMethod as private, it works fine. Can anybody please explain, why is this happening?
Does your TestClass
or any of its superclasses have a @Test
annotation on it? If a class has such an annotation, all public methods are considered test methods.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With