Thursday, March 4, 2010

TestNG Diagnostics

Just a quick note about getting diagnostics from unit tests - if using TestNG, you can configure the dump of detailed test information into the command shell from which you run your tests. Use the verbose property, which you can access via a TestNG object or as part of the testng ant task. This will provide useful insights around failures (stack trace, etc.). For example:

<property environment="env"/>
<testng classpathref="my.classpath"

Here I've used an environment variable to facilitate dynamic levels of verbosity. As per the TestNG Javadoc:

verbose - the verbosity level (0 to 10 where 10 is most detailed) Actually, this is a lie: you can specify -1 and this will put TestNG in debug mode (no longer slicing off stack traces and all).

Given this, I can run my tests like so:

% export verbose=5
% cd /home/mystuff/java/projects/quantum-gravity-dongle/tests
% ant runtests

...and I'll get the diagnostics I need to quickly locate test problems.

No comments:

Post a Comment