SF-PD2 Testing, Debugging, and Deployment Practice Question
A developer is deploying a new Lightning web component that calls an Apex controller method. The deployment to production fails because the Apex class is not covered by tests. The developer needs to ensure the Apex class meets the 75% test coverage requirement and that the tests are robust. Which two actions should the developer take to achieve this? (Choose two.)
⚠ Common exam trap
The trap here is focusing on test utilities like Test.loadData() or @TestVisible as primary solutions, when the core requirement is comprehensive test methods with assertions and branch coverage.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Write test methods that cover all branches of the Apex controller, including positive and negative scenarios.
To meet coverage requirements and ensure robust tests, the developer should write test methods that cover all branches, including positive and negative scenarios, and include assertions that validate outcomes and exception handling. These actions ensure that the Apex controller's logic is thoroughly exercised and verified, which is essential for production deployment.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use @TestVisible private methods to expose internal logic for testing without altering the public API.
Why it's wrong here
@TestVisible is useful for testing private methods, but it does not automatically increase coverage of the controller's main logic. The developer still needs to write test methods that call those exposed methods. It is a tool, not a direct action to achieve coverage. Overuse can lead to testing implementation details rather than behavior.
- ✗
Create test data using Test.loadData() with a static resource to ensure consistent data across test methods.
Why it's wrong here
Test.loadData() is useful for loading large datasets, but it does not inherently improve coverage. Coverage is about executing code lines and branches, not about how data is created. While consistent data can aid testing, it is not a direct action to meet coverage requirements.
- ✓
Write test methods that cover all branches of the Apex controller, including positive and negative scenarios.
Why this is correct
Covering all branches ensures that both successful and error paths are tested, which is essential for meeting coverage requirements and validating behavior. It also helps catch edge cases. This is a best practice for Apex testing and directly contributes to robust coverage.
- ✓
Ensure that the test methods assert expected outcomes and cover exception handling in the controller.
Why this is correct
Assertions validate that the code behaves as expected and are required for meaningful tests. Covering exception handling ensures that error paths are executed, which contributes to branch coverage. This action directly supports robust test coverage and is a Salesforce best practice.
- ✗
Use Test.startTest() and Test.stopTest() to reset governor limits and isolate the test data.
Why it's wrong here
Test.startTest() and Test.stopTest() are used to reset governor limits and test asynchronous code, but they do not directly increase code coverage. They are important for accurate testing but not a primary action to achieve coverage. The focus should be on writing comprehensive test methods.
About these practice questions
One of 226 original SF-PD2 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Salesforce exam blueprint
This SF-PD2 practice question is part of Courseiva's free Salesforce certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the SF-PD2 exam.