How to write kick-ass UnittestsDecember 17th, 2009 • 1 Comment
It doesn’t mater which programming language you are using Java, Python, or something else. Writing cool kick-ass Unit-tests is a must. So here are some thoughts and Ideas:
- Design first & design to test. But do not add extra methods just for testing!
- Always write your unit-test first; It will start small (just checking the public methods) and eventually grow with your code.
- Design and spend time writing test environments with mocks etc.
- Each method should be at least tested by 3 test methods in your unit-test:
- test for success – Test if the method behaves correctly when given parameters in range; this is were the Test-Driven-Development starts.
- test for failure – Test if the method behaves correctly when given invalid parameters, wrong environment etc.
- test for sanity – Test with a set of input parameters and compare results with expected output parameters.
Next to this I would encourage all developers to use Agile development methodologies like Scrum or similar. And also: please tweet and blog to give your users an insight of what is going on with your product/software.
Blog post is also available here