Creating a Test
Unit Test Assistant can analyze your code to generate compilable unit tests for individual methods. It generates runnable test templates that include initial values and sample assertions, which can be easily modified or uncommented.
- If the Unit Test Assistant view is not already open, choose Parasoft> Show View> Unit Test Assistant from the Eclipse menu bar.
- Select a method in the editor.
- Click the Regular action link to create a test for the selected method.
- Uncomment the assertions and modify the default UTA values if necessary.
- Run the test with UTA to collect coverage information and recommendations for possible improvements (see Executing Unit Tests with Unit Test Assistant).
Creating Tests for Private Methods
UTA allows you to create tests for private methods to achieve a higher code coverage rate.
- Enable the Create tests for private methods option in the UTA Preferences (see Test creation options).
- Select a private method in the editor.
- Click the Regular private action link to create a test for the selected method.
By default, the Create tests for private methods option is disabled, because the industry best practice is to test private methods by creating tests for the accessible methods that call them, rather than by creating tests for private methods directly.
Cloning a Test
You can create a new test by cloning an already existing one and modifying the content of the duplicate. You can also clone an existing test as a parameterized test. Refer to Cloning as a Parameterized Test for additional information.
- Select a test in the editor.
- Click the Clone [test name] action link to duplicate the test.
- Modify the duplicated test code.
You can clone one test multiple times. The names of the duplicates will be followed by consecutive numbers.
Creating a Test to Cover a Line
You can create a new test by clicking the Cover the line option in the UTA interface. This will create a test case to cover the testable code line selected in the editor. The values required for the test to cover the line will be automatically set by UTA during generation or will need to be manually configured after the test is created. See Covering a Selected Line for details.