(Old) Tests - LSFN/Design GitHub Wiki
= Unit Tests = We have JUnit tests. These go in the 'test' folder, which has subfolders mirroring the 'src' directory structure.
Run them with 'ant RunTests'. They also get run as part of the build process. You can find a results file in the 'testoutput' folder.
IDEs have functionality for debugging individual tests and displaying test results visually. Depending on the IDE you may need to find a plugin.
Some quick rules of thumb for writing unit tests:
- Make sure all tests are useful. Maintaining tests can suck up a lot of time when you redesign bits of the code base, so don't go testing every single getter and setter.
- Good candidates for writing tests are: code that is used in many places, code that takes some time to comprehend or requires you to 'play computer' by simulating the variables in your head.
- Keep tests short (testing one thing per test method) and their titles descriptive. Ideally, as soon as you see the title of the failed test you should have an idea of what has gone wrong.
- Unit tests are intended for testing a single class or function in isolation.
- Try writing some tests beforehand as part of the design process if you find you're having trouble motivating yourself to do them.
= ToDo: Integration Tests = We don't have integration tests yet. We should probably consider them, because we have multiple programs interacting. It may be worth leaving this until our networking parts have settled down a bit, depending on whether the people developing those parts think it would help or hinder them to have some tests to work with.
We could start with a little script to check whether the network parts will run and connect to each other.
Long term, there are things you can do with fuzzing/generating random input combinations to really shake out all the bugs. Let's not do that yet - maybe in a few months time.