SALESFORCE-PD1 Testing Debugging And Deployment Practice Question
A developer is writing a unit test and needs to assert that a specific custom exception was thrown during invalid input processing. Which pattern should the developer use?
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
✓
Wrap the target code in a try block, add Assert.fail('Expected exception') after the target code, and catch the exception.
Using try-catch blocks with System.assert or Assert.fail inside the try block ensures that if the exception is not thrown, the test fails.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Wrap the target code in a try block, add Assert.fail('Expected exception') after the target code, and catch the exception.
Why this is correct
Placing Assert.fail after the code ensures that if the exception is not thrown, the test fails immediately.
- ✗
Use Test.expectException() before calling the method.
Why it's wrong here
Test.expectException() is not a valid Salesforce Apex test method.
- ✗
Check Limits.getScriptStatements() after the method call.
Why it's wrong here
Checking script statements measures code execution cost, not exception handling.
- ✗
Use System.assert(false, e.getMessage()) inside the catch block.
Why it's wrong here
Putting the assertion inside the catch block means it only executes when caught, which is backward for verifying an exception is thrown.
About these practice questions
Courseiva writes every SALESFORCE-PD1 question from scratch — 488 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. 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 August 2026 · checked against the official Salesforce exam blueprint
This SALESFORCE-PD1 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 SALESFORCE-PD1 exam.