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.
- Make two new Inner Tester Executor services
(Tools | Options... | Debugging and Executing | Execution Types,
right click Execution Types, select New | Inner Tester Executor,
repeat)
- Rename one to JUnit Tester and the other to
JUnit Texter
- 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
- Go to the External Process of JUnit Texter and
insert
junit.textui.TestRunner after {library}
in the argument field
- Add junit.jar to Filesystems
(you can also set Hidden to True in its property sheet)
- 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)
- 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.