import org.testng.IHookCallBack;
import org.testng.IHookable;
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;
import org.testng.SkipException;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import java.util.Iterator;
@Listeners(SampleTestClass.Listener.class)
public class SampleTestClass implements IHookable {
@Test(dataProvider = "dp")
public void testMethod(String name) {
System.err.println("Incoming parameter was " + name);
}
@DataProvider(name = "dp")
public Object[][] getData() {
return new Object[][] {
{"junit"},
{"testng"}
};
}
@Override
public void run(IHookCallBack callBack, ITestResult testResult) {
String parameter = (String) callBack.getParameters()[0];
if (! "junit".equalsIgnoreCase(parameter)) {
callBack.runTestMethod(testResult);
} else {
testResult.setAttribute("disabled", true);
throw new SkipException("Skipping ");
}
}
public static class Listener implements ITestListener {
@Override
public void onTestStart(ITestResult result) {
}
@Override
public void onTestSuccess(ITestResult result) {
}
@Override
public void onTestFailure(ITestResult result) {
}
@Override
public void onTestSkipped(ITestResult result) {
}
@Override
public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
}
@Override
public void onStart(ITestContext context) {
}
@Override
public void onFinish(ITestContext context) {
Iterator<ITestResult> iterator = context.getSkippedTests().getAllResults().iterator();
while (iterator.hasNext()) {
ITestResult result = iterator.next();
if (Boolean.parseBoolean(result.getAttribute("disabled").toString())) {
iterator.remove();
}
}
}
}
}
--
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+unsubscribe@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.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
Getting the same behavior in the IDE plugin is not something it might be able to do.
But then again people run via IDEs only when developing tests. After that you should be worried about only the reports of the execution via a build tool. My testing indicated that this solution works when you run tests via maven.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@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.
--Thanks & Regards
Krishnan Mahadevan"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/My Technical Scribbings @ http://rationaleemotions.wordpress.com/
--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/Wv-84-X8ZgU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to testng-users+unsubscribe@googlegroups.com.