Creating a JUnit Test

See Also 

The JUnit test generator enables you to create compilable test classes for use as skeletons in your unit tests. You can create unit tests for single classes and entire packages, as well as empty test skeletons to be used with sources you create later.

Notes:

To create a test for a single class:

To create a test suite:

  1. Right-click the package node containing the source files for which you want to generate the test suite in the Projects window and choose Tools > Create JUnit Tests (Ctrl-Shift-U) from the popup menu.
  2. Select the JUnit version.
  3. Make sure the Generate Test Suites checkbox is selected, specify any further options, and click OK.

    The IDE generates test classes for all enclosed classes and stores them in the project's Test Packages node. If any of the test classes already exist, those classes are updated.

To create an empty test:

  1. Choose File > New File from the main menu.
  2. In the New File wizard, select JUnit in the Categories pane and JUnit Test in the File Types pane. Click Next.
  3. Specify the test class name, folder and package and select any options you require. Click Finish.
  4. The test skeleton is created based on the properties specified in JUnit Module Settings.

To specify a test directory:

  1. Right-click the project node in the Projects window and choose Properties.
  2. In the Properties window, select Sources in the Categories pane.
  3. Define the properties of the test packages folder in the Test Package Folders list. You can add or remove the folders that are used for test packages and modify the names of the test packages folder as it appears in the Projects window. Click Close.

    Your project must have a test package folder to generate JUnit tests.

JUnit Test Creation Options

When you generate JUnit tests from existing classes, you can specify the following options:

See Also
Running a JUnit Test
Configuring JUnit
About JUnit

Legal Notices