--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
--
Regards / Pozdrawiam
Tomek Kaczanowski
http://practicalunittesting.com
W dniu 22 kwietnia 2012 09:01 użytkownik Krishnan Mahadevan
<krishnan.ma...@gmail.com> napisał:
Hi Sachin, I had a similar problem and the following code works fine
for me.
Class containing test method:
package a;
import org.testng.annotations.Test;
public class NewTest
{
@Test
public void f() throws Exception
{
int a = 5/0;
}
}
Class containing the call to the test method:
package a;
import org.testng.TestNG;
public class TestRunner
{
public static void main(String args[])
{
TestNG testng1 = new TestNG();
testng1.setTestClasses(new Class[]{NewTest.class});
testng1.addListener(new CL2());
testng1.run();
}
}
I then created my own custom test listener CL2 that overrode the
methods of the ITestListener interface
public class CL2 implements ITestListener
{
@Override
public void onTestFailure(ITestResult arg0)
{
// TODO Auto-generated method stub
System.out.println(arg0.getThrowable().getMessage());
StringWriter sw = new StringWriter();
arg0.getThrowable().printStackTrace(new
PrintWriter(sw));
String stacktrace = sw.toString();
System.out.println(stacktrace);
}
}
In this way i was able to get the error message,the stacktrace and
using arg0.getParameters() I was even able to retrieve the parameters
that were passed to the test.
In the case of a try-catch block just convert the exception to an
error and throw the error the test listener will detect the test has
failed.
catch(Exception e)
{
Error e1 = new Error(e.getMessage());
e1.setStackTrace(e.getStackTrace());
throw e1;
}
Hope this helps.
Joel
--
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 http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.