Creating a Unit Test

See Also

The unit test generator enables you to create unit test suites and 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:

  1. Right-click the class in the Projects window and choose Tools > Create Tests (Ctrl-Shift-U) to open the Create Tests dialog box.
  2. Select a unit test framework.
  3. Select the desired code generation options and click OK.

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 Tests (Ctrl-Shift-U) from the popup menu.
  2. Select a unit test framework.
  3. Select the Generate Test Suites checkbox.
  4. Select the desired code generation 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. By default the IDE includes all the test classes as part of the generated test suite.

To create an empty test:

  1. Choose File > New File from the main menu.
  2. In the New File wizard, select JUnit or TestNG in the Categories pane and JUnit Test or TestNG Test Case in the File Types pane. Click Next.
  3. Specify the test class name, folder and package.
  4. Select the desired code generation options and click Finish.

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.
See Also
Running a Unit Test
About Unit Testing

Legal Notices