Challenge - 5 Problems
Code Coverage Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
Understanding coverage output summary
Given the following test coverage summary output from a Node.js project, what is the percentage of statements covered?
Node.js
Statements : 80.0% ( 40/50 ) Branches : 75.0% ( 15/20 ) Functions : 90.0% ( 9/10 ) Lines : 85.0% ( 34/40 )
Attempts:
2 left
💡 Hint
Look for the line labeled 'Statements' and check the percentage.
✗ Incorrect
The 'Statements' line shows 80.0% coverage, meaning 40 out of 50 statements were executed during tests.
❓ component_behavior
intermediate1:30remaining
Effect of missing tests on coverage
If a function in your Node.js code is never called by any test, what will the coverage report show for that function?
Attempts:
2 left
💡 Hint
Think about what happens if code is never executed during tests.
✗ Incorrect
If a function is never called during tests, coverage tools mark it as uncovered, showing 0% coverage.
📝 Syntax
advanced2:00remaining
Correct way to instrument code for coverage
Which of the following commands correctly instruments a Node.js project using nyc for coverage before running tests?
Attempts:
2 left
💡 Hint
nyc is a popular coverage tool that wraps test commands.
✗ Incorrect
The command 'nyc --reporter=lcov mocha' runs mocha tests with nyc coverage instrumentation and outputs lcov reports.
🔧 Debug
advanced2:00remaining
Diagnosing missing coverage data
You ran your tests with coverage, but the report shows 0% coverage for all files. What is the most likely cause?
Attempts:
2 left
💡 Hint
Verify if tests ran successfully and executed the source code.
✗ Incorrect
If the tests did not execute any code (e.g., because they failed to run), the coverage report will show 0% for all instrumented files.
🧠 Conceptual
expert2:30remaining
Interpreting branch coverage results
A coverage report shows 75% branch coverage. What does this mean about your tests?
Attempts:
2 left
💡 Hint
Branch coverage relates to conditional paths, not lines or functions.
✗ Incorrect
Branch coverage measures how many possible paths through if/else or switch statements were tested.