Eliminating the stack trace on test errors

62 views
Skip to first unread message

Jeff

unread,
Nov 22, 2024, 3:00:23 PM11/22/24
to testng...@googlegroups.com
Hi,

I was wondering if it is possible to disable the printing of the stack trace when a test is complete and test failures are displayed?  I do want the message associated with the AssertionErrors, I just don't need the stack trace because it just clutters up the output. 

I'm using:
Maven surefire plugin v3.5.2
TestNG v7.10.2
OpenJDK v17.0.11+9

In the maven-surefire-plugin configuration section of my pom.xml file I have:

 <configuration>
  <verbose>false</verbose>
  <properties>
    <property>
      <name>surefire.testng.verbose</name>
      <value>0</value>
    </property>
  </properties>
</configuration>

I also have a custom listener that clears the throwable value of the ITestResult which reduces the noise before the final report.  

@Override
public void onTestFailure(ITestResult tr) {
    Throwable th = tr.getThrowable();
    if (th != null && th instanceof AssertionError) {
        tr.setThrowable(null);
    }
    super.onTestFailure(tr);
}

Without the listener, I get a dump of the failure for each test case (with stacktrace) before the final report, and then a duplicate message for every test failure (with stacktrace again) in the final report.  Now I only have the errors + stacktraces in the final report but I'd like to only show the message associated with the AssertionError or Exception, but without stack traces.  Any pointers on how to do this?

Thanks!

Jeff

Jeff

unread,
Nov 22, 2024, 3:16:17 PM11/22/24
to testng...@googlegroups.com
I should also note that I'm using org.testng:reportng:1.2.2

Thanks!

Krishnan Mahadevan

unread,
Nov 25, 2024, 12:42:55 AM11/25/24
to testng...@googlegroups.com
Jeff,

Have you tried setting the JVM argument “testng.show.stack.frames” to true and see if that helps ?


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 Scribblings @ https://rationaleemotions.com/

--
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 view this discussion visit https://groups.google.com/d/msgid/testng-users/CAPJK9%3DLLjNr7LXvj_zrU2wYKPo7GT1P4%2BKmSCdQ93NrnQhdfWg%40mail.gmail.com.

Jeff

unread,
Nov 25, 2024, 1:11:19 AM11/25/24
to testng...@googlegroups.com
I haven't, but wouldn't the default be what I want? I hope to not have the stack frames shown.

I'll try explicitly setting it to false tomorrow.

Thanks,

Jeff 

Reply all
Reply to author
Forward
0 new messages