Question 1 of 29
A developer is tasked with writing a test class for an Apex class that processes orders. The class contains a method that calculates the total price of an order based on the quantity of items and their individual prices. The method is designed to throw an exception if the quantity is negative or if the price is zero. The developer needs to ensure that the test class covers both positive and negative scenarios, including edge cases. Which of the following approaches should the developer take to ensure comprehensive test coverage?
Create multiple test methods that assert the total price for valid quantities and prices, and also include test methods that assert exceptions are thrown for negative quantities and zero prices.
Write a single test method that checks the total price for a valid order and assumes that the exception handling is implicitly tested.
Focus only on testing the exception handling by creating test methods that only check for negative quantities and zero prices, ignoring valid scenarios.
Use a mock service to simulate the order processing and only test the integration with the service, without directly testing the Apex class.

Preparing for SalesForce DEV-501 Apex and Visualforce Controllers? Now land the interview.

73% of qualified candidates get rejected because of weak resumes. Build an ATS-optimized, recruiter-ready resume in under 5 minutes - free to start.

Build My Resume Free