Cortex: Unit Tests
A Unit Test exercises a chunk of code in isolation, and verifies that it is doing the right thing over a whole range of inputs. Not everything can be easily unit tested (e.g. GUIs), but you'll be surprised how much can be when you get into the habit, and usually if you find a module that can't be tested in isolation it is because the interface to that module isn't as clean as it should be, so unit tests also encourage good design.
Unit tests are required for all code in Cortex, but for your own sake you really should be writing your unit tests first, then writing the code to make them work. If you do it this way it usually turns out to be quicker than coding without the tests (because you catch things really early), and certainly a lot quicker than having to go back and add them afterwards.
- If you find a bug that isn't exposed by the unit tests, add a test that catches it BEFORE fixing the bug
- Try to write your unit tests first, then write the code to make them work. When all the tests pass you know you're done.
- Graphics software is particularly well suited to unit testing, you can write out an image, node graph or object at any point and compare it to a benchmark file
