Test Coverage Improvements
Summary
Current test coverage is 16% with several critical production files having 0% coverage. This document tracks necessary test additions and fixes to reach target coverage of 60-70%.
Critical Issues (0% Coverage)
1. NetMonDaemon.cpp (358 lines, 0% covered) 🔴 HIGH PRIORITY
Problem: No integration tests exist for the HTTP daemon that serves metrics endpoints.
Required Tests:
Implementation:
// filepath: tests/integration/test_netmon_daemon.cpp
- Start daemon in background thread
- Make HTTP requests using httplib
- Verify responses and status codes
- Clean shutdown after tests
Estimated Coverage Gain: +215 lines (~60% of file)
2. PcapAdapter.cpp (86 lines, 0% covered) 🔴 HIGH PRIORITY
Problem: test_pcap_adapter.cpp exists (47 lines) but produces no coverage data. Test is likely failing silently or not running.
Investigation Needed:
Required Tests:
Implementation:
// filepath: tests/unit/test_pcap_adapter.cpp
- Use GTEST_SKIP() if not running as root
- Test with sample.pcap file instead of live interface
- Mock pcap_* functions for unit testing
- Add privilege check before interface tests
Estimated Coverage Gain: +60 lines (~70% of file)
3. StatsPersistence.cpp (78 lines, 0% covered) 🟡 MEDIUM PRIORITY
Problem: No tests for SQLite database operations (save/load stats).
Required Tests:
Implementation:
// filepath: tests/unit/test_stats_persistence.cpp
- Use `:memory:` SQLite database for tests
- Create sample AggregatedStats with known values
- Verify round-trip save/load preserves data
- Test error conditions (disk full, permissions, etc.)
Estimated Coverage Gain: +62 lines (~80% of file)
4. main.cpp (58 lines, 0% covered) 🟢 LOW PRIORITY
Problem: CLI entry point has no functional tests.
Required Tests:
Implementation:
// filepath: tests/integration/test_main.cpp
- Use system() to invoke ./netnet binary
- Capture stdout/stderr
- Verify exit codes
- Test argument combinations
Estimated Coverage Gain: +17 lines (~30% of file)
Medium Priority Issues
5. test_pcap_adapter.cpp (47 lines, 0% covered)
Problem: Test file itself has no coverage, indicating it's not running.
Action Items:
6. Parser.cpp (49 lines, 59% covered)
Problem: Missing edge case coverage.
Additional Tests Needed:
Estimated Coverage Gain: +20 lines (→ 100%)
7. ConnectionTracker.cpp (59 lines, 79% covered)
Problem: Missing coverage for edge cases.
Additional Tests Needed:
Estimated Coverage Gain: +12 lines (→ 100%)
8. StatsAggregator.cpp (56 lines, 92% covered)
Problem: Near-complete but missing edge cases.
Additional Tests Needed:
Estimated Coverage Gain: +4 lines (→ 100%)
Testing Infrastructure Improvements
CI/CD Pipeline
Test Fixtures
Test Organization
Excluded from Coverage (Vendor Code)
The following files are intentionally excluded from coverage metrics:
include/net-net/vendor/httplib.h (2175 lines) - Third-party HTTP library
include/net-net/vendor/bcrypt.cpp (45 lines) - Third-party crypto library
include/net-net/vendor/uuid_gen.cpp - UUID generation utility
Total vendor lines: ~2220 (should not count toward coverage goals)
Coverage Goals
| Metric |
Current |
Target |
Stretch Goal |
| Overall Coverage |
16% |
60% |
70% |
| src/ Coverage |
25% |
70% |
85% |
| Critical Files (NetMonDaemon, PcapAdapter) |
0% |
60% |
80% |
| Unit Test Coverage |
~86% |
90% |
95% |
Estimated Timeline
Phase 1: Critical Fixes (Week 1)
- Fix
test_pcap_adapter (not running)
- Add basic
test_netmon_daemon (HTTP endpoint smoke tests)
- Expected gain: 16% → 25%
Phase 2: Core Coverage (Week 2)
- Complete
NetMonDaemon integration tests
- Add
StatsPersistence unit tests
- Expand
Parser edge case tests
- Expected gain: 25% → 45%
Phase 3: Comprehensive Testing (Week 3)
- Add
main.cpp functional tests
- Add end-to-end integration tests
- Performance and stress tests
- Expected gain: 45% → 60%
Phase 4: Polish (Week 4)
- Reach for 70% coverage
- Add fuzz testing
- Valgrind clean runs
- Documentation updates
- Expected gain: 60% → 70%
Related Issues
Notes
- Current test suite takes ~6 seconds to run (mostly
SessionManager sleep tests)
- Consider mocking time in
SessionManager tests to speed up CI
- PcapAdapter tests may need elevated privileges in CI
- NetMonDaemon tests need to bind to ephemeral ports to avoid conflicts
Last Updated: December 8, 2025
Owner: @guns4kids
Priority: High - Blocking production readiness
Test Coverage Improvements
Summary
Current test coverage is 16% with several critical production files having 0% coverage. This document tracks necessary test additions and fixes to reach target coverage of 60-70%.
Critical Issues (0% Coverage)
1. NetMonDaemon.cpp (358 lines, 0% covered) 🔴 HIGH PRIORITY
Problem: No integration tests exist for the HTTP daemon that serves metrics endpoints.
Required Tests:
/api/metricsendpoint returns valid JSON/api/flowsendpoint returns flow data/api/sessionsendpoint with authenticationImplementation:
Estimated Coverage Gain: +215 lines (~60% of file)
2. PcapAdapter.cpp (86 lines, 0% covered) 🔴 HIGH PRIORITY
Problem:
test_pcap_adapter.cppexists (47 lines) but produces no coverage data. Test is likely failing silently or not running.Investigation Needed:
./build/test_runnerRequired Tests:
Implementation:
Estimated Coverage Gain: +60 lines (~70% of file)
3. StatsPersistence.cpp (78 lines, 0% covered) 🟡 MEDIUM PRIORITY
Problem: No tests for SQLite database operations (save/load stats).
Required Tests:
saveStats()writes to database successfullyloadStats()retrieves saved stats correctlyImplementation:
Estimated Coverage Gain: +62 lines (~80% of file)
4. main.cpp (58 lines, 0% covered) 🟢 LOW PRIORITY
Problem: CLI entry point has no functional tests.
Required Tests:
--helpflag displays usage--versionflag displays version-i eth0)Implementation:
Estimated Coverage Gain: +17 lines (~30% of file)
Medium Priority Issues
5. test_pcap_adapter.cpp (47 lines, 0% covered)
Problem: Test file itself has no coverage, indicating it's not running.
Action Items:
6. Parser.cpp (49 lines, 59% covered)
Problem: Missing edge case coverage.
Additional Tests Needed:
Estimated Coverage Gain: +20 lines (→ 100%)
7. ConnectionTracker.cpp (59 lines, 79% covered)
Problem: Missing coverage for edge cases.
Additional Tests Needed:
Estimated Coverage Gain: +12 lines (→ 100%)
8. StatsAggregator.cpp (56 lines, 92% covered)
Problem: Near-complete but missing edge cases.
Additional Tests Needed:
Estimated Coverage Gain: +4 lines (→ 100%)
Testing Infrastructure Improvements
CI/CD Pipeline
Test Fixtures
Test Organization
Excluded from Coverage (Vendor Code)
The following files are intentionally excluded from coverage metrics:
include/net-net/vendor/httplib.h(2175 lines) - Third-party HTTP libraryinclude/net-net/vendor/bcrypt.cpp(45 lines) - Third-party crypto libraryinclude/net-net/vendor/uuid_gen.cpp- UUID generation utilityTotal vendor lines: ~2220 (should not count toward coverage goals)
Coverage Goals
Estimated Timeline
Phase 1: Critical Fixes (Week 1)
test_pcap_adapter(not running)test_netmon_daemon(HTTP endpoint smoke tests)Phase 2: Core Coverage (Week 2)
NetMonDaemonintegration testsStatsPersistenceunit testsParseredge case testsPhase 3: Comprehensive Testing (Week 3)
main.cppfunctional testsPhase 4: Polish (Week 4)
Related Issues
Notes
SessionManagersleep tests)SessionManagertests to speed up CILast Updated: December 8, 2025
Owner: @guns4kids
Priority: High - Blocking production readiness