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:
- open a page, wait for it to load, and take a screenshot for you to see;
- run scripts inside the page to check component state and console errors;
- simulate clicks and typing to test interaction flows.
A few practical tips:
- Wait long enough before taking a screenshot. 3D, charts and CDN resources take a few seconds to load. Sometimes the screenshot tool captures an old frame, so have code wait before capturing.
- When you can’t get past the login page, build a test page that loads the real JS / CSS and replaces the API calls with stub functions.
- Plant a deliberate error to confirm the check itself works: for example, put a broken expression into a template and confirm the compile check really raises a warning.
V. Tests can be wrong too
In practice, there were two cases where the test itself was at fault:
- The inline script on the test page contained a literal
</script>, which cut the script short and made the whole test time out; - One assertion was still written for the old behavior. After the fix,
0012should stay as text, but the assertion expected it to be converted to the number 12.
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:
- A script inside an iframe ran before layout finished, when its width was 0, so the canvas stayed blank → a resize event is now sent uniformly from the bridge layer;
- After a component navigated to another page, the
pagehidemessage was not always delivered → now it counts the iframe’sloadevents instead; - The effect description only stripped the angle brackets, so
<b>Heat</b>becamebHeat/b→ now the whole tag is stripped.
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.