Building Good Testing Habits
As a beginner, you should be OK with what not to test on day one, but it’s important to start picking it up by day two. Forming bad habits of over-testing early on can be hard to shake later. Consider the cost of preventing a bug. Don’t aim for 100% coverage. High code-to-test ratios are a red flag. For example, avoid testing standard Active Record associations, validations, or scopes in Ruby on Rails applications.
TDD (Test-Driven Development) is a discovery tool/process. It provides evidence for conclusions and enables rapid experimentation for quick feedback. Don’t force yourself to test-first every component. A ratio of 20% test-first and 80% test-after is a practical approach. Focus on understanding what’s worth testing beyond common examples.
Unnecessary indirection reduces design cohesiveness. TDD confirms desired design in the face of change and isolates critical pieces of the system for flexibility. Testing exposes message communication between objects — separate database request-response cycles from unit tests for better relevance to business needs.
Balanced test suites ensure long-term maintainability. Improve the efficiency and flexibility of tests for more accessible updates to application functionality. Unit tests and acceptance tests are essential for tested application features. Good unit test coverage catches edge cases and confirms object behavior. Use tests as scaffolding and pare down the suite to a minimal set for necessary confidence.
[¹]: Practical Object-Oriented Design: An Agile Primer Using Ruby