FeaturesPluginsDocs & SupportCommunityPartners

JUnit style of use

This message courtesy of Fokko Degenaar explains how to use the Inner Testers module to run JUnit tests (at least as of JUnit 3.2). Refinement courtesy Richard Hensley. Comments and confirmations are welcome.

But first check out the JUnit module, which may be what you really want, unless you specifically prefer tests inside the source code itself.


  1. Make two new Inner Tester Executor services (Tools | Options... | Debugging and Executing | Execution Types, right click Execution Types, select New | Inner Tester Executor, repeat)
  2. Rename one to JUnit Tester and the other to JUnit Texter
  3. Go to the External Process of JUnit Tester and insert junit.swingui.TestRunner after {library} in the argument field. This modification starts the harness with the inner class as an argument instead of starting the inner class directly
  4. Go to the External Process of JUnit Texter and insert junit.textui.TestRunner after {library} in the argument field
  5. Add junit.jar to Filesystems (you can also set Hidden to True in its property sheet)
  6. Open the accompanying JUnitTestableClass.java and save it as template inside the Java Classes template category with the name JUnitTestableClass (right-click the source in the Explorer and choose Save As Template..., or copy into Tools | Options... | Source Creation and Management | Templates | Java Classes)
  7. Modify the template's properties by selecting Tools | Options... | Source Creation and Management | Templates | Java Classes | JUnitTestableClass and selecting the Execution tab:
    • Compiler: Inner Tester Compiler
    • Executor: JUnit Tester
    By default the graphical test harness will be used. If text output is needed then set Executor to JUnit Texter (on the template to set defaults for newly created testable classes, or individually on existing classes).
Ready! Writing unit tests should be fun now.
Companion
Projects:
MySQL Database Server   Open JDK: an Open SourceJDK   GlassFish Community: an Open Source Application Server    Mobile & Embedded Community    Open Solaris   java.net - The Source for Java Technology Collaboration   Virtual Box - full virtualizer  Open ESB - The Open Enterprise Service Bus Powered by