unit tests can be co-located with code
Generally test suites live in separate files from the code they test. Historically, this was advantageous from the perspective of compiler development. Files that compile file individually and then link the resulting files together because it allows excluding test code from release executables. However, it would be advantageous to co-locate tests with code because:
- tests act as documentation, making the code easier to understand
- it makes relocating top level functions easier, there is no need to also move the test
- it makes tests in context for LLMs by default
In order to make this feasible it is necessary to either:
- use conditional compilation1
- link-time dead code elimination
- accept the fact that your executable will be a little larger.
I do this in wiki-language-server and I like it quite a bit.
conditional compilation makes linting/compiling code in an ide environment difficult
See also:
-
be careful becauseĀ ↩