public class DPSample {
public static void main(String[] args) {
TestNG testNG = new TestNG();
testNG.setTestClasses(new Class[] {SimpleTestClass.class});
testNG.setVerbose(2);
IReport report = new IReport();
testNG.addListener(report);
testNG.run();
Set<ITestResult> failedTests = report.getFailedResults();
for (ITestResult failedTest : failedTests) {
String className = failedTest.getInstance().getClass().getName();
String methodname = failedTest.getMethod().getMethodName() + "()";
String parameters = Arrays.toString(failedTest.getParameters());
System.err.println("***" + className + methodname + parameters + " failed.");
}
}
public static class SimpleTestClass {
@Test (dataProvider = "dp")
public void hello(int a) {
if (a == 0) {
throw new IllegalArgumentException("Zeroes are not accepted.");
}
System.err.println("Hello " + a);
}
@DataProvider (name = "dp")
public Object[][] getData() {
return new Object[][] {
{1}, {0}, {2}
};
}
}
public static class IReport implements IReporter {
private Set<ITestResult> failedResults = new HashSet<>();
@Override
public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {
for (ISuite suite : suites) {
Map<String, ISuiteResult> suiteResults = suite.getResults();
for (ISuiteResult result : suiteResults.values()) {
failedResults.addAll(result.getTestContext().getFailedTests().getAllResults());
}
}
}
public Set<ITestResult> getFailedResults() {
return failedResults;
}
}
}
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.