Questions and answers
- Does every method in every class have to have its own unit test?
No. That seems to be a common view, but it is harmful. If we use that approach, we are locking in the implementation details and will not be able to refactor without breaking tests.
- What is the significance of 100% code coverage when running our tests?
Not much, by itself. It simply means that all the lines of code in the units under the test were executed during the test run. For us, it means a little more due to our use of test-first TDD. We know that every line of code was driven by a meaningful test of behavior that is important to our application. Having 100% coverage is a double-check that we didn’t forget to add a test.
- Does 100% code coverage during the test run mean we have perfect code?
No. Testing can only reveal the presence of defects, never their absence. We can have 100% coverage with very low-quality code in terms of readability and...