Concept Flow - Why testing matters
Write Code
Write Tests
Run Tests
Confident
Run Tests Again
This flow shows how writing and running tests helps catch bugs early, leading to confident code or fixing issues before release.
function add(a, b) {
return a + b;
}
console.log(add(2, 3)); // 5| Step | Action | Input | Output | Result |
|---|---|---|---|---|
| 1 | Call add function | 2, 3 | 5 | Correct sum returned |
| 2 | Run test: add(2,3) === 5 | 2, 3 | true | Test passes |
| 3 | Change code to function add(a, b) { return a - b; } | 2, 3 | -1 | Incorrect sum |
| 4 | Run test again | 2, 3 | false | Test fails, bug detected |
| 5 | Fix code back to function add(a, b) { return a + b; } | 2, 3 | 5 | Correct sum restored |
| 6 | Run test again | 2, 3 | true | Test passes, confident code |
| Variable | Start | After Step 3 | After Step 5 | Final |
|---|---|---|---|---|
| add function | a + b | a - b (buggy) | a + b (fixed) | a + b (correct) |
Why Testing Matters: - Write tests to check your code works. - Run tests to catch bugs early. - Fix bugs when tests fail. - Re-run tests to confirm fixes. - Testing builds confidence in your code.