Salesforce Platform Developer I (legacy) — Question 79

How should a developer write unit tests for a private method in an Apex class?

Answer options

Correct answer: D

Explanation

The correct answer is D, as the TestVisible annotation allows private methods to be tested by making them visible to the test methods. Option A is incorrect because simply adding a test method does not enable access to private methods. Option B is wrong since marking a class as global changes its visibility but does not directly relate to testing private methods. Option C is also incorrect because SeeAllData is generally discouraged for unit testing due to potential data contamination.