testng-team / testng

TestNG testing framework
https://testng.org
Apache License 2.0
1.98k stars 1.02k forks source link

Feature request: selecting overloaded test methods (suite file and/or eclipse plugin) #1294

Open Prakash-Saravanan opened 7 years ago

Prakash-Saravanan commented 7 years ago

TestNG Version

Note: only the latest version is supported 6.10

Expected behavior

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.

Actual behavior

It executes all the methods with that name.

Is the issue reproductible on runner?

Test case sample

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" } };
    }

}
Prakash-Saravanan commented 7 years ago

When running as an XML file, it will run all the methods. Is this an expected behavior with Eclipse runner too?

krmahadevan commented 7 years ago

@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.

juherr commented 7 years ago

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?

krmahadevan commented 7 years ago

@juherr - I think that makes sense to add a warning (at-least) informing the user of multiple overloaded versions of the same test method.