Unit tests verify that a single unit of code (function, class method) behaves correctly in isolation. Key properties: fast (milliseconds), isolated (no I/O, DB, or network), deterministic (same result every run), focused (one behaviour per test). Pattern: Arrange (setup), Act (call the unit), Assert (verify output). Test doubles (mocks, stubs, spies) replace real dependencies. Aim for 80%+ meaningful coverage, not 100% superficial coverage.
Arrange-Act-Assert unit test structure.
Tests that verify internal implementation details (method was called with these exact parameters) break when you refactor. Test the observable result: given input X, output is Y. This allows safe refactoring.
100% line coverage achieved by testing trivial getters and setters gives false confidence. Cover your complex business logic, edge cases, and error paths at 80%+ rather than padding shallow coverage.
Stryker mutates your production code (changes > to >=, removes return values) and runs your tests. Tests that pass all mutations aren't actually verifying anything useful. Mutation score > 70% indicates real test quality.
Sign in to share your feedback and join the discussion.