Why Tests Matter
By the end of this lesson, you'll be able to:
- Explain what a unit test actually verifies
- Distinguish automated tests from the manual Execute Anonymous verification used in Modules 26, 27, and 30
- Recognize Salesforce's 75% code coverage requirement as a floor, not a goal
Prerequisites: Module 30: "Project: Customer Support"
What Modules 26, 27, and 30 have been missing
Every project since Module 26 has ended with an Execute Anonymous script confirming the feature worked at that moment. But nothing about that verification survives — if someone changes AccountRollupService next month, nothing re-runs those checks automatically. A test class is Apex code that verifies other Apex code, and — critically — it runs automatically every time the org is deployed to, catching a regression the instant it's introduced.
What a test actually verifies
@isTest
private class CalculatorTest {
@isTest
static void additionWorksCorrectly() {
Integer result = 2 + 2;
System.assertEquals(4, result, 'Expected 2 + 2 to equal 4');
}
}
@isTest (first previewed in Module 13's Annotations lesson) marks this entire class as test-only code. Inside it, additionWorksCorrectly() sets up a scenario, runs the code being tested, and asserts the actual result matches the expected one — the exact same shape as every manual verification since Module 26, just automated and permanent.
The 75% coverage requirement is a floor, not a goal
Salesforce requires at least 75% of an org's Apex code to be covered by tests before it can be deployed to production — but hitting exactly 75% coverage says nothing about whether the tests actually verify anything meaningful. This module's final lesson, "Code Coverage vs Meaningful Testing," returns to this distinction directly — for now, the key idea is: coverage is a deployment gate, not evidence the code actually works correctly.
Exercise
As a comment, explain the key difference between the Execute Anonymous verification used in Module 26 and an automated test class.
Show hint
Think about what happens after the verification runs once.
Why Tests Matter Quiz
My Notes
Log in to keep private notes on this lesson.
Questions about this lesson
No questions yet — be the first to ask.
Log in to ask a question about this lesson.
Summary
Every "Test the Feature" lesson since Module 26 has manually verified a feature once, by hand — this module introduces automated tests that verify it every time, automatically, forever.