Unit test generator

The test generator creates compilable test classes, which are skeletons for your unit tests. Test skeletons are generated according to tested classes and the process of generation can be custmized by changing the configuration of Unit test generator. Generated skeletons are runnable under the JUnit framework.

Generation of skeletons

Tes skeletons are created for chosen class or package. Generator creates skeletons for all classes in the package and for all accessible inner classes. If one or all of test classes exists, than such class or classes will be updated, if necessary. Test classes are stored in FileSystem, that was selected as a target file system for tests. Generated test classes are compilable and runable.

cfg_create.gif

Configuration of JUnit tests generator

Test generator can be easily configured by the above dialog box. Generally it consists from three parts allowing to aet up the target file system, templates and code generation. Following sections describe their meaning in details.

File system:
Test classes are generated under the special file system, it separates them from the tested code. This separation is pretty good idea, because usually you don't want to distribute the test code alongside classes comprising your product. Here you can choose the target file system from all file systems mounted in your IDE or you can mount new one by pressing the Mount button. Newly mounted file system is automatically selected as a target file system for test generation. In fact, new file system is mounted only, when you confirm your settings by pressing the OK button, that's why, it is displayed as 'unreachable'.

Templates:
Templates are source files used as base for generation of all test classes. Generally, there two kinds of test classes are generated for you - test classes and suite classes - you can easily recognize them by the 'Test' and 'Suite' words appended to the class name. You can define as much of templates as you wich and choose from them in this dialog (see the IDE documentation for more details about templates). Templates can be useful for generation different tests, e.g. the test classes for performance test could have additional code for measurements initialization or your company rules force you to place the license informatoin at top of all your source files.

Code generation:
Set of options held under the 'Code generation' frame allows you to set up the code generator exactly as you need. You can turn off creation of functions with the same accessibility level, e.g. you want to test only the interface of your classes and aren't interested in testing functions visible only within the package (switch off Package functions generation). Test classes generator is able to create comments or JavaDoc commnets for tested functions. Also it can generate simple code printing the name of the test function. Usually you will not want to generate test classes for exceptions, because they will be empty in bulk of cases, but you can change this behavior by setting the 'Include Exceptions' flag. When you require advanced functionality of JUnit provided by NetBeans extension to JUnit (NbJUnit), you can set generator to geneate tests inherinting from NbTestCase. You can also desire to regenerate suite() method in the test and suite classes. All of this functionality you can use or not just by clicking the mouse.

The last option called 'Show me this dialog' can be used to turn of this dialog, when you deselect this option, the dialog will not be displayed later. You have to set this option manually from the Project|Settings to allow again displaying of this dialog.