Understanding Code Coverage
What is code coverage as reported by unit test coverage tools?
- The proportion of code lines executed during testing
- The percentage of code lines commented
- The number of commits that contain tests
- The ratio of test files to source files
- The amount of code deleted during a test run
Interpreting Coverage Thresholds
If a coverage report shows 85% line coverage and your minimum threshold is 90%, what does this imply?
- You need to write more tests to cover additional code
- All code branches have been fully tested
- The coverage is above the required threshold
- There are syntax errors in your tests
- Coverage tools need to be re-installed
Analyzing Missed Lines
Given the code snippet: if (user == null) { throw new Error('Invalid'); }, what does it mean if this line is marked as uncovered?
- The test suite never triggers a null 'user' value
- This line was commented out during testing
- The function is never called in the codebase
- Coverage tool cannot analyze conditional statements
- The code was not compiled
Excluding Files from Coverage
Which statement best describes the effect of excluding a file from coverage reporting?
- The file's lines will not impact overall coverage percentage
- Excluded files will be tested twice
- Coverage for excluded files is shown as 100%
- It will reduce the number of bugs in the file
- Coverage reports will auto-delete the file
Branch vs. Line Coverage
What is the main difference between branch coverage and line coverage in a coverage report?
- Branch coverage checks all possible paths; line coverage counts executed lines
- Branch coverage is slower to compute than line coverage
- Line coverage includes test file lines, branch does not
- Branch coverage is only used in Python, not JavaScript
- Line coverage requires manual analysis
Improving Low Coverage
After viewing your coverage report, you notice several untested functions. What should you do to improve your test coverage?
- Add new unit tests targeting the untested functions
- Delete the functions from the codebase
- Decrease the coverage threshold
- Turn off code coverage tools
- Commit untested code to main branch
False Coverage Readings
What could cause the coverage report to falsely indicate that code is covered?
- Tests execute lines but do not verify outcomes (assert no assertions)
- Coverage tools are run with debug mode off
- All code is written in one file
- Test failures are ignored during test runs
- Coverage files are stored in the wrong directory
Reading HTML Coverage Reports
When using a coverage tool that outputs HTML reports, which color typically indicates uncovered code?
- Red
- Blue
- Green
- Yellow
- Purple
Coverage and Continuous Integration
Why integrate code coverage checks into a continuous integration (CI) pipeline?
- To automatically enforce test coverage levels before merging code
- To increase compilation speed
- To reduce the test file size
- To generate additional test files automatically
- To convert JavaScript code to Python
Interpreting Coverage Summary
If your coverage summary shows functions: 90%, statements: 95%, and branches: 80%, what should you investigate further?
- Review branch coverage for untested conditional logic
- Stop writing additional tests since coverage is high
- Add comments to all functions
- Reduce the number of branches in your code
- Ignore the coverage report