Test Generation
The test generator creates compilable test classes, which are skeletons
for your unit tests. Test skeletons are generated according to tested classes.
The process of generation can be custmized by changing the configuration
of the unit test generator. Generated skeletons are runnable by the
JUnit framework.
Generation of Skeletons
Test skeletons are created for the chosen class or package. The generator creates
skeletons for all classes in the package, based on the rules set in the Create
Tests dialog box. If any of the test classes already exist, those classes are
updated if necessary. Test classes are stored in the filesystem that was selected
as a target filesystem for the tests. The generated test classes
are compilable and runable.
Configuration of the JUnit Test Generator
You can configure the test generator in the Create Tests dialog box. You can
set the target filesystem, templates, and code generation rules.
The following describes the different parts of the Create Tests dialog box:
- File Systems combo box. Choose a target filesystem from a list of all of the
filesystems that are mounted in your IDE. It is a good practice to generate tests in a special
filesystem, which separates the tests from the tested code. Typically
you would not want to distribute the test code alongside the classes that
comprise your application.
- Templates panel. Templates are source files that are used as the basis for
generation of all test classes. There are two kinds of test classes that are generated:
- Test classes, which contain the actual tests.
- Suite classes, which are used to group test classes for execution.
You can define as many templates as you want and choose them in this dialog box.
Templates that are used for test generation have to be stored in the JUnit
folder in the New wizard.
Templates
are useful for creating standard text or code in your test classes, such as license
information in your source files. You also might want to create templates for
different types of tests. For example, test classes
for performance testing could have additional code for initialization
measurements. See
Templates for
more details about creating and using templates in the IDE.
- Code Generation panel. A group of options that allows you to set
up the code generator exactly as you need. The available options are:
- Public Methods. If selected, test methods are generated for
methods with public member access.
- Protected Methods. If selected, test methods are generated
for methods with protected member access.
- Package Methods. If selected, test methods are generated
for methods with default (package private or just package) member access.
- Comments. If selected, the generated test bodies include
simple hints.
- JavaDoc. If selected, every generated test method contains
a simple JavaDoc comment.
- Include Abstract Classes. If selected, abstract classes
are included in test generation.
- Include Exception Classes. If selected, exception classes are
included in test generation.
- Include Package Private Classes. If selected, classes with
package private (default) access are included for test generation.
- Default Bodies. If selected, the generated test bodies
contain code that prints the name of the function and causes the test
to fail with message: The test case is empty. If false, the test bodies
are empty.
- Generate Suites. If selected, suite classes for each package
are generated.
- Show Create Tests Configuration Dialog checkbox. If selected,
the Create Tests dialog box is displayed whenever you choose the Create Tests command. If you
unselect this checkbox, you can later change this setting in the Options window.
 |
All settings that you change in this dialog box remain
in effect until you change them again, either in this dialog box or in the
JUnit Module Settings. |
Legal Notices