Class JUnitReportHelper

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

public class JUnitReportHelper extends 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.
  • Field Details

  • Constructor Details

    • JUnitReportHelper

      public JUnitReportHelper(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 Details

    • msg

      private void msg(String str)
    • checkCurrent

      private void checkCurrent()
    • start

      public void start(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(String msg)
      Report that the current test failed with an error message.
    • fail

      public void fail(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(String msg, long duration)
      Report that the current test failed with an error message.
    • fail

      public void fail(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.