Apex Test Class Generator

Paste an Apex class and get a test class skeleton — setup data, one test per public method, and the right pattern for batch, scheduled, queueable and callout code.

Test class

A starting point, not a finished test: fill in the TODOs with real data and assert on real results. Private methods are covered through the public ones that call them.

Runs in your browser — nothing you paste is sent to us or stored.

How to use it

  1. 1

    Paste your class

    The whole class, from “public class” to the last brace. Comments and strings are fine.

  2. 2

    Get the skeleton

    A @TestSetup method and one test per public or global method — with Batch, Schedulable, Queueable and callout patterns where they apply.

  3. 3

    Fill in the TODOs

    Replace placeholder values with realistic data and the asserts with the results you expect, then run the tests.

Questions

How much code coverage does Salesforce need?

To deploy Apex to production, at least 75% of your Apex code must be covered by tests, all tests must pass, and every trigger needs some coverage. Coverage alone isn’t the goal: tests should assert that the code does the right thing, which is why this tool leaves the assertions for you to complete.

Why does every test use Test.startTest() and Test.stopTest()?

Code between them gets a fresh set of governor limits, separate from the setup work. Test.stopTest() also makes asynchronous work — @future methods, Queueable jobs, batches and scheduled jobs — run right away, so you can assert on its results straight after.

What is @TestSetup for?

It creates test records once for every test method in the class, and each test sees a fresh copy. Tests don’t see your org’s real data by default, so the setup must create everything the code needs.

How do I test code that makes HTTP callouts?

Tests can’t call real endpoints. Implement HttpCalloutMock to return a fake response and register it with Test.setMock(HttpCalloutMock.class, new MockResponse()) before the code runs. When the class makes callouts, the generator adds a mock for you to fill in.

What about private methods?

Test them through the public methods that call them. If you really need to reach one directly, mark it @TestVisible — but testing behaviour through the public surface usually gives better tests.

Is my code sent anywhere?

No. The class is read and the test class written in your browser; nothing is uploaded.

Further reading

Want to go beyond the tools?

Learn Salesforce development — live classes with people who build on Salesforce every day.

See the learning path →