PDI · Question #105
What writing an Apex class, a developer warts to make sure thai all functionality being developed Is handled as specified by the requirements. Which approach should the developer use to be sure that…
The correct answer is A. Create a test class to execute the business logic and run the test in the Developer Console. To ensure an Apex class functions as specified by requirements, a developer should create a dedicated test class to execute its business logic and verify outcomes.
Question
What writing an Apex class, a developer warts to make sure thai all functionality being developed Is handled as specified by the requirements. Which approach should the developer use to be sure that the Apex class is working according tospecification?
Options
- ACreate a test class to execute the business logic and run the test in the Developer Console.
- BInclude a savepoint and Database,rollback.
- CInclude a try/catch block to the Apex class.
- DRun the code in an Execute Anonymous block n the Deceloper Consider.
How the community answered
(65 responses)- A88% (57)
- B2% (1)
- C5% (3)
- D6% (4)
Why each option
To ensure an Apex class functions as specified by requirements, a developer should create a dedicated test class to execute its business logic and verify outcomes.
Creating a test class allows developers to write specific test methods that invoke the business logic of the Apex class with controlled data, assert expected outcomes, and ensure the code works according to specifications and requirements.
Including a savepoint and Database.rollback is primarily for transaction control during runtime and doesn't inherently validate the overall business logic against requirements.
Including a try/catch block is for error handling within the Apex class and does not validate the functional correctness of the business logic.
Running code in an Execute Anonymous block is for ad-hoc testing or script execution, not for systematic validation and verification against requirements or ensuring repeatable test coverage.
Concept tested: Apex testing best practices
Source: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_code.htm
Topics
Community Discussion
No community discussion yet for this question.