4. Agenda
• Why write Unit Tests in Apex?
• Understanding Test Code Coverage
• Blueprint of a Test Class
• Executing Unit Tests
• Best Practices for Unit Testing
• Trailhead Modules
• Q&A
5. Some Housekeeping Rules…
• Mute your mic
• Keep adding questions in Zoom Q&A Window
• No questions are silly!
• Questions will be answered in the last 15 mins of this session
11. Executing Unit Tests
• Run executions
o All unit tests
o Some or all methods of specific class
o Some or all methods of a set of classes
o Predefined suite of classes – Test Suite
• How to run?
o Salesforce user interface
o Force.com IDE
o Lightning Platform Dev Console
o API
13. Becoming a Pro at Unit Tests
• Accessing Private Data Members in a Test Class
• @Testvisible
• Running Test Code within Limits
• Test.startTest()
• Test.stopTest()
• Creating Test Data without Code
• Test.loadData()
• Impersonating Users in Unit Tests
• System.runAs()
14. Best Practices for Testing
Test for Use case & not Code Coverage
Check for all scenarios – valid, invalid, bulk and restricted User
Use System.assert to prove the code behaves properly
Create your Test Data
Create test data before Test.startTest
State the assumptions the tester made about the data, the
expected outcome etc. in code comments
Never test your entire application in a single test.
•