PD1 Testing, Debugging & Deployment 2 — Questions and Answers
Question 1: Which System.assert method should you use when you want to verify that two values are equal in an Apex test?
- System.assert(val1, val2)
- System.assertEquals(val1, val2) (Correct answer)
- System.assertNotEquals(val1, val2)
- System.assertMatch(val1, val2)
Correct answer: System.assertEquals(val1, val2)
System.assertEquals(expected, actual) compares two values and fails the test if they are not equal.
Question 2: What is the minimum test code coverage percentage required to deploy Apex to a Salesforce production org?
- 50%
- 60%
- 75% (Correct answer)
- 100%
Correct answer: 75%
Salesforce requires at least 75% aggregate test code coverage across all Apex code to deploy to production.
Question 3: Which class is used to set mock responses for callouts in Apex tests?
- Test.setMock() (Correct answer)
- Callout.setMock()
- HttpMock.set()
- Test.setCalloutMock()
Correct answer: Test.setMock()
Test.setMock() registers a mock implementation that intercepts HTTP callouts during test execution.
Question 4: What happens when you run a Salesforce deployment with the 'checkOnly' flag set to true?
- The deployment is committed to production
- A validation is performed without saving components (Correct answer)
- Only metadata is deployed, not Apex
- Code coverage is skipped
Correct answer: A validation is performed without saving components
A checkOnly deployment validates all components and runs tests without persisting any changes to the org.
Question 5: Which annotation marks an Apex method as a test setup method that runs once before any test methods in the class?
- @testSetup (Correct answer)
- @isTest(setup=true)
- @beforeAll
- @TestFixture
Correct answer: @testSetup
@testSetup creates a single set of test data that is rolled back and re-created for each test method.
Question 6: What tool in Salesforce allows developers to view debug logs filtered by user or by log category?
- Developer Console (Correct answer)
- Workbench
- Apex Explorer
- Schema Builder
Correct answer: Developer Console
The Developer Console provides a log panel where you can filter, open, and analyze debug logs by user and category.
Question 7: In a sandbox-to-production deployment, which of the following is NOT deployed by the Change Set process?
- Apex classes
- Custom objects
- User records (Correct answer)
- Validation rules
Correct answer: User records
Change Sets deploy metadata (configuration and code) but do not migrate data records such as user records.
Which System.assert method should you use when you want to verify that two values are equal in an Apex test?