When you're developing an application, it will eventually form a structure and evolve into a stable product that you can use in production and sell to your customers. In the beginning, everything may seem simple and many tend to postpone the construction of a proper test suite.
Later on, the application may become just sufficiently complex for you to hesitate to begin testing. You may eventually give up and never test your application. It may be frustrating, especially if you have never seen or used any test suite before.
Proper testing gives you more than a little bit of quality assurance. Proper testing gives you:
- Predictability: This means that your code execution, no matter if it's an application or just a module, will have an expected result. As you evolve the tests and introduce different test cases, you begin to fulfill all the uses for your code, and you ensure its results were as intended.
- Feature coverage: This means that you can measure what parts of your code are tested or not. There are plenty of tools to inspect your code and tell you what parts of it haven't been used in your test suite, which helps you create specific tests for specific parts of the code that are not yet covered.
- Safe evolution: This is a side effect. When your code gets complex, if your test suite has good code coverage, you can make changes and add features without compromising stability, as you can continuously run the test suite and see if it breaks anything.
There's a developing methodology that involves first creating a test for a new feature and then making sure the test passes. This way, you can focus on how you think your code should be used (in the new test) and then evolve it (actually develop it) so the test stops failing and gives proper results.
Let's see how code coverage can help in the testing process. Finally, we'll look at how you can mock parts of your code.