GSalesforceGyan
← Browse learning guides

Apex

Testing that proves behavior

Write tests for business outcomes, bulk input, and failure recovery.

By Vishal Verma · Reviewed October 5, 2026

Practice these questions aloud. Give the principle, explain a concrete example, and finish with how you would verify the result.

1. What makes a test useful beyond coverage?

Suggested answer: Assertions prove expected results and error behavior. Include positive, negative, bulk, and boundary cases. Coverage measures execution, not whether the code delivers the requirement.

Scenario / follow-up: Assert that invalid input cannot create a record, rather than only asserting that code ran.

2. Why use startTest and stopTest?

Suggested answer: They isolate the tested execution with a fresh governor-limit context and allow supported asynchronous work enqueued during the test to execute at stopTest. Do not assume arbitrary chains of background jobs all complete.

Scenario / follow-up: Keep setup outside the pair and assert outcomes afterward.

3. How do you test HTTP callouts?

Suggested answer: Use HttpCalloutMock to return controlled responses. Assert request details and test success, error status codes, and malformed responses. Keep tests independent of an external service.

Scenario / follow-up: A timeout or failed request must not result in a false success message.

Reviewed October 5, 2026. Check the linked documentation for your org’s API version and supported features.

Official reference

Read the Salesforce documentation or Trailhead resource