To use this functionality, OpenAI must first be configured in the Parasoft Preferences. For details, see Configuring OpenAI Settings.
This feature depends on OpenAI, which may produce inaccurate information.
Follow these steps to improve a selected test with AI:
- Select a test method in the editor and then click the Improve [method_name] with AI button in the Unit Test Assistant view.
2. The Improve [method_name] with AI window appears.
Specify the following:
- Improvement type: Select the type of improvement you want to make.
- Convert to parameterized test - Converts the selected test to a parameterized format with rows of data to cover different code paths.
- Add edge and error cases - Expands the test to include additional input value cases to cover as many lines of code in the method under test as possible.
- Custom - Makes changes to the test based on user-provided instructions.
- Prompt history: Select a prompt. The drop-down list contains default example prompts and previously submitted prompts.
- User prompt text area: Include any extra details/instructions you would like to submit to OpenAI.
3. Click Submit to send the query to OpenAI and receive a result.
OpenAI returns the results as a stream of text. In most cases this will be the updated version of the test, but it might also include an explanation of the code.
The initial OpenAI response for the unit test improvements is always in English. When the language selected for Jtest is Chinese or Japanese, the Translate button is also available, which enables users to translate the initial response into their language. The button will be disabled if the original response from OpenAI was empty or if the result has already been translated.
4. To apply the AI-generated solution, copy the recommended code snippet using the Copy code option and paste it into the existing test file or a new file.
If multiple snippets are returned, only the first code snippet is copied.