Function and Method Coverage
You'll learn what function and method coverage measures and why knowing if functions are called at all is a powerful first-pass test quality signal.
The Core Idea
Function and method coverage tracks whether each function or method in your codebase is executed at least once during your test runs. It doesn't care how many lines inside a function run or which branches get taken—it only asks: "Did this function ever get called?"
Think of it like a roll-call for your code. If a function never shows up during testing, it's essentially completely untested. You have no idea if it works, breaks, or even compiles correctly in practice.
Why This Matters
Function coverage is a coarser metric than line or branch coverage, but it's incredibly useful for finding blind spots:
- A function with 0% function coverage means it's never invoked by tests
- This often reveals dead code, forgotten utilities, or important logic nobody remembered to test
- It's a quick scan: if you have 100 functions and only 80 are covered, you know exactly which 20 need attention
Real-World Example
Imagine you have a sendWelcomeEmail() method. Line coverage might show that the function exists and compiles. But if function coverage reports it at 0%, you know no test ever calls it—meaning the entire email-sending feature is untested, regardless of how many lines it contains.
Complementing Other Metrics
Function coverage is a first filter. A function at 100% function coverage might still have poor branch coverage inside. But a function at 0% is a red flag that deserves immediate investigation.
Key Takeaway:
Function and method coverage identifies completely untested functions—a critical, easy-to-spot signal of missing test scenarios and potential dead code.