Why test?
AI writes code that looks perfect and is wrong. A test is your safety net: it shouts when things break. The moment a test catches a hallucination.
Your first test
A test is just code that throws when the result doesn't match. Write one by hand, no framework, to grasp the mechanics.
Arrange-Act-Assert
The universal grammar of a test: arrange, act, assert. And the rule that separates a good test from a bad one: test behavior, not implementation.
What to test, what to skip
Testing everything wastes time; testing nothing is dangerous. A clear rule to choose, and why 100% coverage proves nothing.
Red first
A test that was never red tests nothing. The assertTrue(true) trap, and why you (sometimes) write the test before the code.
The TDD cycle
Red → green → refactor: the fastest feedback loop in dev. And the "Is TDD dead?" debate, settled honestly, no dogma.
Mocks and stubs
Isolate what you test: replace the database, network and clock with doubles. And the golden rule: mock as little as possible.
Your tests in a real project
The sandbox was for learning. Enter Vitest: install it, run your tests in watch mode, in CI, and read coverage without getting fooled.
The pyramid and AI code
Unit, integration, end-to-end: how much of each. And the full workflow to test AI-generated code without getting fooled.
What you will learn
Write a test that goes red then green, by hand then with the right structure
Choose what to test (and what to skip), and why 100% coverage proves nothing
Practice the red-green-refactor TDD cycle, and know when it's worth it
Test AI-generated code to catch its logic bugs before production
Prerequisite: being able to read and write a bit of JavaScript (variables, functions, conditions). If not yet, start with the JavaScript course. All examples are in JavaScript and run in your browser; the ideas apply to every language (PHP, Python, Go…).