Creating JUnit tests
To develop JUnit tests follow these steps to set-up your project:
- Create a Java project
- Open the project's build path property page and add the junit.jar contained
in the org.junit plugin of your Eclipse install as an external JAR.
- If you want to avoid absolute pathnames on the build classpath you can introduce
a class path variable and reference the junit.jar relative to this variable.
- If you want to browse the JUnit source then attach the src.jar contained
in the org.junit plugin to the junit.jar.
- Implement a TestCase subclass with some tests and build them.
You can also use the TestCase wizard:
- Open the new wizard dialog by doing one of the following:
- pressing Ctrl+N or
- selecting File > New > Other from the menu bar or
- pressing the Open the New Wizard toolbar button or
- Select Java > Junit in the left pane and TestCase in the
right pane
- Press Next
- In the Source Folder field, enter the name of the source folder in
which your test will be created. You can use the Browse button and
select the source folder from the resulting dialog.
- In the Package field, enter the name (empty name denotes the default
package) of the package in which your test will be created. You can use the
Browse button and select the package from the resulting dialog.
- In the Test case field, enter the name for the test you are creating.
- In the Test class, enter (optionally) the name of the class that
your test will be testing. Selecting a class for testing will later allow
you to create test methods for public method in the selected class.
- In the Superclass field, enter the name of the superclass of your
test (this class must implement the
junit.framework.Test
interface).
- Use the checkboxes to select the methods that you want to create in the
test.
- If you left the Test class field empty, then press Finish
to create the test.
- If you entered the name of the class to be tested, then:
- press Finish to create the test without generating test methods
or
- press Next to select the public methods that you want to test
- Use the checkbox tree control to select the methods for which you want the
wizard to create tests
- Select the Create tasks for generated Test methods if you want to
add tasks that will remind you to implement the test methods
- Press Finish

Using JUnit
JUnit preference page