Re: Suppress Assert stack trace?

1,049 views
Skip to first unread message

edwolb

unread,
Nov 22, 2012, 12:48:45 PM11/22/12
to testng...@googlegroups.com
I think that this might be implemented by the default TestNG listeners.  Our listeners for example choose what to output to the console.  We actually end up filtering the stack traces to include only code that we have written, which reduces some stack traces from 30+ lines to 3-5 lines.

On Thursday, 22 November 2012 02:35:36 UTC-5, sirdan wrote:
Is there a way to suppress the java.lang.AssertionError stack trace that appears in the console when an exception is thrown? It doesn't provide much useful info (i.e. expected [true[ but found ]false]) and it would be nice to have the option to get rid of it, so it doesn't clutter other output. thanks -dan

sirdan

unread,
Dec 14, 2012, 2:32:56 AM12/14/12
to testng...@googlegroups.com
Thanks for the suggestion, I'll try it.



--
View this message in context: http://testng.1065351.n5.nabble.com/Suppress-Assert-stack-trace-tp17276p17451.html
Sent from the testng-users mailing list archive at Nabble.com.

sirdan

unread,
Dec 14, 2012, 2:59:05 PM12/14/12
to testng...@googlegroups.com
For others who encounter this, here's some code that will strip out the stack trace:

import org.testng.ITestResult;

import org.testng.TestListenerAdapter;


public class NoTrace extends TestListenerAdapter {

 

  @Override

  public void onTestFailure(ITestResult tr) 

  {

Throwable thrown = tr.getThrowable();

StackTraceElement[] outTrace = new StackTraceElement[0];

thrown.setStackTrace(outTrace);

  }

 

  @Override

  public void onTestSkipped(ITestResult tr) 

  {

  }

 

  @Override

  public void onTestSuccess(ITestResult tr) 

  {

  }

 

}

Reply all
Reply to author
Forward
0 new messages