Generate unit test scenarios
Stay organized with collections
Save and categorize content based on your preferences.
When writing unit tests for your app, Gemini can suggest test scenarios using
the context of the code you want to test. When generating unit test scenarios,
Gemini includes detailed names and descriptions for your tests, so that you
better understand the intention for each suggested test. You need to implement
the body of each test yourself.
To generate unit test scenarios, do the following:
- Navigate to the class you want to generate unit test scenarios for.
- Right-click on the class name and select
Gemini > Generate Unit Test Scenarios from the context menu.
- In the dialog that appears, select the methods of the class that you want to
generate scenarios for, and set the destination package for the tests.
- Click OK.
- Confirm the destination directory for your tests and click OK.
- If the test class already exists, confirm whether you want Gemini to suggest
updates to the existing file.
After Gemini processes the request, you should see either a new file with the
suggested unit tests or a diff for you to accept recommended changes to an
existing file.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-07-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-31 UTC."],[],[],null,["# Generate unit test scenarios\n\nWhen writing unit tests for your app, Gemini can suggest test scenarios using\nthe context of the code you want to test. When generating unit test scenarios,\nGemini includes detailed names and descriptions for your tests, so that you\nbetter understand the intention for each suggested test. You need to implement\nthe body of each test yourself.\n\nTo generate unit test scenarios, do the following:\n\n1. Navigate to the class you want to generate unit test scenarios for.\n2. Right-click on the class name and select **Gemini \\\u003e Generate Unit Test Scenarios** from the context menu.\n3. In the dialog that appears, select the methods of the class that you want to generate scenarios for, and set the destination package for the tests.\n4. Click **OK**.\n5. Confirm the destination directory for your tests and click **OK**.\n6. If the test class already exists, confirm whether you want Gemini to suggest updates to the existing file.\n\nAfter Gemini processes the request, you should see either a new file with the\nsuggested unit tests or a diff for you to accept recommended changes to an\nexisting file."]]