org.glassfish.pfl.test
Class JUnitReportHelper

java.lang.Object
  extended by org.glassfish.pfl.test.JUnitReportHelper

public class JUnitReportHelper
extends java.lang.Object

Helper class for generating reports for tests that do not adapt well to Testng/JUnit. For example, several tests re-run the same test method and class many times with different parameters. JUnit does not support this at all. Testng does, but it is too much work to adapt these tests. Instead, we can just bracket test case execution with start/(pass|fail) calls.


Nested Class Summary
static class JUnitReportHelper.Counts
           
 
Constructor Summary
JUnitReportHelper(java.lang.String cname)
          Prepare to generate a JUnitReport in the file named ${junit.report.dir}/${name}.xml.
 
Method Summary
 JUnitReportHelper.Counts done()
          Testing is complete.
 void fail(java.lang.String msg)
          Report that the current test failed with an error message.
 void fail(java.lang.String msg, long duration)
          Report that the current test failed with an error message.
 void fail(java.lang.Throwable thr)
          Report that the current test failed with the given exception as cause.
 void fail(java.lang.Throwable thr, long duration)
          Report that the current test failed with the given exception as cause.
 void pass()
          Report that the current test passed.
 void pass(long duration)
          Report that the current test passed.
 void start(java.lang.String name)
          Start executing a test case with the given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JUnitReportHelper

public JUnitReportHelper(java.lang.String cname)
Prepare to generate a JUnitReport in the file named ${junit.report.dir}/${name}.xml. junit.report.dir is obtained from the environment variable which is passed to all CTF controllers.

Parameters:
cname - The class name of the class for this test
Method Detail

start

public void start(java.lang.String name)
Start executing a test case with the given name. All names MUST be unique for an instance of JUnitReportHelper.

Parameters:
name - The name of the test case

pass

public void pass()
Report that the current test passed.


fail

public void fail(java.lang.String msg)
Report that the current test failed with an error message.


fail

public void fail(java.lang.Throwable thr)
Report that the current test failed with the given exception as cause.


pass

public void pass(long duration)
Report that the current test passed.


fail

public void fail(java.lang.String msg,
                 long duration)
Report that the current test failed with an error message.


fail

public void fail(java.lang.Throwable thr,
                 long duration)
Report that the current test failed with the given exception as cause.


done

public JUnitReportHelper.Counts done()
Testing is complete. Calls to start, pass, or fail after this call will result in an IllegalStateException. This method may be called multiple times, but only the first call will write a report.