Hacker News new | ask | show | jobs
by RyanMcGreal 4819 days ago
Unit tests are merely approximations of what challenges you can imagine your application will need to face. An analogy can be drawn to the body of precedent in case law.
1 comments

Precedent only deals with regression, which is also useful to document in code, but should not be your only source of documentation.

The purpose of testing, though oft missed due to the name we have given it, is to document your code. The tests explain intent, usage, etc. that can often not be conveyed by the code alone. Verification that the documentation does what it claims comes as an added bonus, of course, and is why we recommend testing over writing comments. Though comments can also be useful in certain situations – right tool for the job and all that.

I feel like law could benefit greatly from something that mirrors TDD, not only to help convey intent of the law, which is information often lost as years pass, but also to help third-parties better understand what the law says. The exact same reasons why we write tests for code. Starting to write that documentation after the code is already in production, so to speak, seems too late.

Law is like code. Documentation is nice. For law it's widely available. But all that counts is the law. Well-written documentation is not a substitute and a court will not give you leeway if you were mislead by mistaken documentation.

In common law countries, the entire process of law is actually a black box functional test. And again: that's the only test that counts. Everything else might be wrong.