Note: only the latest version is supported
6.10
Having more than one methods in a class with same name and different signature (method overloading) and selecting (by double clicking the method name) and running one test method, it should run the selected method alone.
It executes all the methods with that name.
import org.testng.ITestContext;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class TestNGIssue {
@Test
public void test() {
System.out.println("test without param");
}
@Test
public void test(ITestContext context) {
System.out.println("test with param as itestcontext");
}
@Test(dataProvider = "data")
public void test(String name) {
System.out.println("test with param as string");
}
@DataProvider(name = "data")
public Object[][] dataprovider() {
return new Object[][] { { "name" } };
}
}
When running as an XML file, it will run all the methods.
Is this an expected behavior with Eclipse runner too?
@Prakash-Saravanan - I think that's the expected behaviour. TestNG resorts to reflection to find methods, but it doesn't differentiate methods based on their signatures, but resorts to finding methods based on ONLY names. So IMO this is not an issue but TestNG is working as designed.
Could be an improvement on test selection or, at least, testng may warn if it found many methods with the same name.
@krmahadevan @cbeust What do you think?
@juherr - I think that makes sense to add a warning (at-least) informing the user of multiple overloaded versions of the same test method.
Most helpful comment
@Prakash-Saravanan - I think that's the expected behaviour. TestNG resorts to reflection to find methods, but it doesn't differentiate methods based on their signatures, but resorts to finding methods based on ONLY names. So IMO this is not an issue but TestNG is working as designed.