Unit testing
Real stupidity beats artificial intelligence every time.
Terry Pratchett.
Testing your application cannot be reduced to test that your application normal use would work, you have to test that every piece of code works at it should.
Unit testing consist on identifying and consistently verifying each software unit, checking inputs, state and outputs of an specific function.
To write proper unit testing, you should follow a guideline.
Identify units:
In object oriented programming, a unit might be a function or method. The scope is the determinant issue, if the scope is too narrow, the test could be too obvious, if the scope is too broad you could miss testing parts of the code.
Identify requirements:
The purpose of the unit, had to be crystal clear, no input, output, state or functionallity can be missed.
Write the test according to the requirements:
Ideally, Test Driven Development determine writing the tests before the code. But even if you don’t do that, you should write your tests watching the requirements, not looking through the code, this way you won’t be tempted to write the tests that will work with your code, instead of writing right code that will pass the tests.
Test everything.
Not just the output, test every possible output, input and the state of the object after the execution.
References:
IEEE Standard for Software Unit Testing.