Claude Code tutorials · Part 05

Testing and automated verification

Don’t accept “it should be fine”. Have it prove the change is correct with a build, tests and screenshots.

I. Three levels of verification

Level Method Catches
Does it run? Compilation, syntax checks Typos, wrong signatures, syntax errors
Is the logic right? Unit tests, method-level tests Edge cases, error branches, business rules
Does it look right? Browser screenshots, page automation Misaligned styles, blank areas, broken interactions

After every change, have it pass at least the first level, pass the second level for key logic, and pass the third level for page changes.

II. Compile only what changed

A full build of a large project can take several minutes. You can have it compile only the classes it changed:

Don’t do a full build. Use javac to compile only the few classes changed this time, with the classpath exported by mvn dependency:build-classpath.

Run front-end JS through a syntax check at least once (for example node --check). Templates can be compiled once with the framework’s own compiler to check for warnings.

III. Test business logic without starting the whole service

A lot of logic depends on AI, databases or external services, which makes it awkward to start the whole application. You can have it instantiate the real classes directly and swap the external dependencies for fakes:

Write a test: directly new up XxxServiceImpl, use a Java dynamic proxy to build a fake AI service, return different content depending on the scenario (normal HTML, non-HTML, content containing sensitive words, overly long content), use reflection to call these private methods, and verify the result of each case.

This way, dozens of scenarios can run in one go. In practice, this kind of test ran 47 checks, covering rules such as “fall back to a chart when AI fails”, “a maximum of 3 components”, and “rewrite the component after a column change”.

The key point: you are testing the real code and only replacing the external dependencies, rather than writing a separate mock version of the logic to test instead.

IV. Page verification: headless browser

Verify front-end changes with a headless browser such as Playwright. It can:

A few practical tips:

V. Tests can be wrong too

In practice, there were two cases where the test itself was at fault:

So when a test fails, first work out whether the code is wrong or the test is wrong. Don’t change the code just to make the test pass.

VI. Real bugs found by testing

Good tests turn up problems along the way. In practice, testing and screenshots uncovered and fixed the following:

Wrap-up

After every change, ask yourself (and have it answer too): what evidence shows it is correct? A change counts as done only when it has all three: it compiles, the tests pass, and the screenshots have been checked.