Apex Test Case Generation

Unit tests must cover at least 75% of your Apex code, and all of those tests must complete successfully for your code to be deployed or packaged for AppExchange. Use Agentforce for Developers to quickly generate unit tests for your Apex classes. Test case generation is enabled by default.

Apex Test Case Generation

Use Agentforce for Developers to quickly generate Apex unit tests.

  1. Right-click in an Apex file in the editor, and select Agentforce: Generate an Apex Test or click the beaker icon on the top right to open the Test Case Generation panel.
  2. Select Apex. Then select the method for which you want to generate unit tests.
  3. When prompted, choose to create a new test class file or select an existing test class to which to add the test. If you choose to create a new file, the command uses the naming convention, <ApexClassFileName>Test.cls for the new file. The command adds the test method to the new file.
  4. Review the generated unit test method and choose to Accept, Try Again, or Clear.
  5. To generate another test method, right-click within the class file or the test class file and again select Agentforce: Generate an Apex Test.

You can generate a test using one of these keyboard shortcuts:

Operating SystemGenerate Test
macOS⌘ ⌥ T
Windowswin ⌥ T
Linuxwin ⌥ T

This is a list of known issues with Apex test case generation. The team is working on them internally. For issues related to Agentforce for Developers, check our github repo.

  • Currently, test data isn’t generated alongside a test generation.