9 lessons · 93 min Intermediate

Testing your code — your guardrail when coding with AI

AI writes fast and fails silently. Learn to write tests that catch its mistakes before production — in JavaScript, runnable in your browser.

FR EN
Progress 0/9
1

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.

8 min
2

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.

10 min
3

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.

9 min
4

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.

9 min
5

Red first

A test that was never red tests nothing. The assertTrue(true) trap, and why you (sometimes) write the test before the code.

10 min
6

The TDD cycle

Red → green → refactor: the fastest feedback loop in dev. And the "Is TDD dead?" debate, settled honestly, no dogma.

12 min
7

Mocks and stubs

Isolate what you test: replace the database, network and clock with doubles. And the golden rule: mock as little as possible.

11 min
8

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.

11 min
9

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.

13 min

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…).

Start lesson 1

Free · No signup · 8 minutes