This is very much possible and still supported in TestNG.
Here's a complete sample that shows all of this in action.
I am using TestNG 6.13.1 for this (This is the latest released version of TestNG as of today)
Sample test class
package com.rationaleemotions.stackoverflow.qn48171506;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class SampleTestClass {
@Test
@Parameters(value = "name")
public void helloA(String name) {
System.err.println("helloA() says " + name);
}
@Test
@Parameters(value = "anotherName")
public void helloB(String name) {
System.err.println("helloB() says " + name);
}
@Test
@Parameters(value = "someOtherName")
public void helloC(String name) {
System.err.println("helloC() says " + name);
}
}
Sample test listener
package com.rationaleemotions.stackoverflow.qn48171506;
import org.testng.IInvokedMethod;
import org.testng.IInvokedMethodListener;
import org.testng.ITestResult;
public class TestListener implements IInvokedMethodListener {
@Override
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
showMessage("About to run ", method, testResult);
}
@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
showMessage("Completed running ", method, testResult);
}
private static void showMessage(String prefix, IInvokedMethod method, ITestResult testResult) {
String msg = prefix + method.getTestMethod().getMethodName() + "() with the parameters " +
method.getTestMethod().findMethodParameters(testResult.getTestContext().getCurrentXmlTest());
System.err.println(msg);
}
}
Suite xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Sample_Suite" verbose="2">
<listeners>
<listener class-name="com.rationaleemotions.stackoverflow.qn48171506.TestListener"/>
</listeners>
<test name="sample_test" verbose="2">
<classes>
<class name="com.rationaleemotions.stackoverflow.qn48171506.SampleTestClass">
<methods>
<include name="helloA">
<parameter name="name" value="Jack"/>
</include>
<include name="helloB">
<parameter name="anotherName" value="Daniel"/>
</include>
<include name="helloC">
<parameter name="someOtherName" value="Craig"/>
</include>
</methods>
</class>
</classes>
</test>
</suite>
Execution output
...
... TestNG 6.13.1 by Cédric Beust (cedric@beust.com)
...
About to run helloA() with the parameters {name=Jack}
helloA() says Jack
Completed running helloA() with the parameters {name=Jack}
About to run helloB() with the parameters {anotherName=Daniel}
helloB() says Daniel
Completed running helloB() with the parameters {anotherName=Daniel}
About to run helloC() with the parameters {someOtherName=Craig}
helloC() says Craig
Completed running helloC() with the parameters {someOtherName=Craig}
PASSED: helloA("Jack")
PASSED: helloB("Daniel")
PASSED: helloC("Craig")
===============================================
sample_test
Tests run: 3, Failures: 0, Skips: 0
===============================================
===============================================
Test Dependencies
Total tests run: 3, Failures: 0, Skips: 0
===============================================