JUnit

This plugin provides a java command creator to execute JUnit test cases in a module and a target to generate a global report.

Declaration

  <plugin name="junit">
    <attribute name="junit.jar" value="junit-3.8.1.jar"/>
  </plugin>

Dependencies

  • runtime and compile

Usage

At execution unit or module level, you have to declare the following attribute to enable JUnit support:

  <attribute name="junit.runnable" value="true"/>

It is exactly equivalent to add the junit.jar global attribute as jar dependency to the module and to add the following runtime attributes:

  <attribute name="runtime.runnable" value="true"/>
  <attribute name="runtime.command.creator" value="runtime.command.creator.junit"/>

Now, the module declared as runnable will have a start.module.eu shortcut in the build.xml file. Call one of start.module.eu.mymodule.myeu or startdev.module.eu.mymodule.myeu (or eventually without .myeu if the module has no execution unit declared) will execute JUnit with all the module's selected test cases.

An XML report per test case is generated in dist/junit.

As a shortcut, invoke junit.start.all or junit.startdev.all targets will run all junit modules declared in the project.

Then the set reports can be generated with junit.report that collects all available test cases XML reports in dist/junit for a module set and writes a global HTML report in ${reports.directory}/junit/SET or in dist/junit/SET if reports directory is not set.

If the website plugin is configured, the reports.directory is used and a report entry is added to the project reports overview.

To clean reports, the junit.clean.report target can be used.

Advanced usage

Change default runner

You can change default runner globally with the attribute junit.default.runner set in the plugin configuration. You may also set the runner to use for a specific module execution unit with the junit.runner attribute or just for a command invocation with the property set -Djunit.runner=junit.swingui.TestRunner (for instance) when a runtime target is called with a JUnit module.

Run a specific TestSuite

By default, the JUnit runner execute the suite method of the ch.elca.el4ant.junit.CollectionSuite class to detect TestCase implementation in the module classes directory.

To prevent test case detection, you may set the junit.collectionsuite.suite attribute with a TestCase class name or a class name with a static suite method. This attribute can be set on a specific module execution unit, or set for a command invocation with the property -Djunit.collectionsuite.suite=mypackage.MyTestCase on the command line.

XML reports are generated for the selected suite.

Change default TestSuite

By default, the JUnit runner execute the suite method of the ch.elca.el4ant.junit.CollectionSuite class to detect TestCase implementation in the module classes directory.

You may want to run your own suite, providing a subset of test cases to the runner. It can be done for a specific module execution unit with the junit.suite attribute or just for a command invocation with the property -Djunit.suite=mypackage.MyTestCase set when a runtime target is called with a JUnit module. The class must be a JUnit TestCase or provide a static suite method that returns a JUnit TestSuite. Of course, the specified class must be available in the ClassPath.

As far as the EL4Ant CollectionSuite is responsible to generate XML reports, setting the suite to run prevent reports to be generated.

Hide execution output

The attribute junit.collectionsuite.showoutput may be set on a module or an execution unit to prevent test execution output to be published on the Ant console. Its default value is true. This attribute can also be set on the execution command line to hide output for this single run with -Djunit.collectionsuite.showoutput=false. Even if output is hiden, it is stored in XML reports.

Attributes

Global

  • junit.jar is the jar name to use as dependency. Default value is junit.jar.
  • junit.set is the set name to add to junit modules. Default value is empty, in that case, no change is done on module sets.
  • junit.set.list is the list of module sets for which reports are generated. Default value is the list of known module sets.
  • junit.default.runner is the default JUnit runner used to run test suite.

Per execution eu

  • junit.runner is the JUnit runner used to run test suite in the concerned module execution unit. Default value is the value set to junit.default.runner. This attribute may be set to a module if no execution unit is declared.
  • junit.collectionsuite.showoutput is a switch to hide Java test execution output on the Ant console. Default value is true.
  • junit.collectionsuite.suite is a TestCase name class or a class name with a suite method. This class is run by the CollectionSuite if set. Default behaviour of the CollectionSuite is to detect available test cases.
  • junit.suite is a TestCase name class or a class name with a suite method. Default value is ch.elca.el4ant.junit.CollectionSuite.

Targets

  • junit.start.all calls start.module.eu on all execution unit modules that are configured to be run with JUnit.
  • junit.startdev.all calls startdev.module.eu on all execution unit modules that are configured to be run with JUnit.
  • junit.report generates the test reports for all set in the dist/junit directory or in the reports.directory.
  • junit.report.set generates the test report for a specific set.
  • junit.clean.report cleans the generated test reports for all module sets.
  • runtime.command.junit.creator is the java command creator to use as execution unit runtime.command.creator.

Hooks

  • pre.junit.report and post.junit.report are called before and after the set report generation.

ToDo

  • Support JAR for binary module
  • Report JVM crash and exit

Revision: r1.10 - 03 Feb 2006 - 15:07 - YvesMartin
EL4Ant > PlugIns > PluginJUnit
Copyright © 2004 by ELCA. All material on this collaboration platform should not be disclosed outside of ELCA.
Ideas, requests, problems regarding TWiki? Send feedback.