You can track test coverage in Replit by running coverage.py for Python projects or istanbul/nyc for Node.js projects directly in the Shell tab. These tools measure which lines of your code are executed during tests and generate reports showing uncovered code. Add a coverage script to your .replit run command or package.json to integrate coverage tracking into your workflow.
Measure Test Coverage in Replit to Find Untested Code
This tutorial walks you through setting up code coverage reporting in Replit so you can see exactly which parts of your codebase are tested and which are not. You will install a coverage tool, run your test suite with coverage tracking enabled, read the coverage report to identify untested code, and set a minimum coverage threshold to enforce quality standards. Coverage reports run entirely in the Shell and Console — no external services needed.
Prerequisites
- A Replit account (free Starter plan works)
- A Replit App with existing tests (pytest for Python or jest/mocha for Node.js)
- Basic familiarity with the Replit Shell tab
- At least one test file in your project
Step-by-step guide
Install the coverage tool in Shell
Install the coverage tool in Shell
Open the Shell tab in your Replit workspace. For Python projects, install coverage.py which works with pytest, unittest, and any other Python test framework. For Node.js projects, install nyc (the command-line interface for istanbul) which works with jest, mocha, and other JavaScript test frameworks. Both tools are lightweight and install in seconds.
1# For Python projects:2pip install coverage pytest34# For Node.js projects:5npm install --save-dev nycExpected result: The coverage tool installs successfully. Running 'coverage --version' or 'npx nyc --version' in Shell confirms the installation.
Run your tests with coverage tracking
Run your tests with coverage tracking
Execute your test suite with coverage tracking enabled. For Python, prefix your test command with 'coverage run'. For Node.js, prefix with 'npx nyc'. The tool monitors which lines of source code are executed during the test run and records the results. After the tests complete, generate a coverage report that shows the percentage of lines covered per file.
1# Python — run tests with coverage:2coverage run -m pytest3coverage report45# Python — see which specific lines are missed:6coverage report -m78# Node.js — run tests with coverage:9npx nyc mocha1011# Node.js with jest (built-in coverage):12npx jest --coverageExpected result: A table appears in the Shell showing each source file with its coverage percentage, number of statements, and missed lines.
Read the coverage report and identify gaps
Read the coverage report and identify gaps
The coverage report shows a table with columns for each file: Stmts (total statements), Miss (statements not executed during tests), Cover (percentage covered), and Missing (specific line numbers not covered). Focus on files with low coverage percentages and look at the Missing column to find exactly which lines need tests. Lines in error handling blocks, edge cases, and fallback logic are commonly uncovered. Aim for 80% or higher coverage on critical business logic.
1# Example Python coverage output:2# Name Stmts Miss Cover Missing3# --------------------------------------------------4# app/main.py 45 12 73% 23-28, 41-455# app/utils.py 30 3 90% 15, 22, 296# app/database.py 55 20 64% 30-507# --------------------------------------------------8# TOTAL 130 35 73%910# Lines 23-28 in main.py and 30-50 in database.py need testsExpected result: You can read the coverage report and identify which files and line numbers need additional tests.
Add a coverage script for easy re-running
Add a coverage script for easy re-running
Create a reusable script so you can run coverage checks quickly. For Python, create a script or add the commands to your .replit run command. For Node.js, add a coverage script to your package.json. This makes it easy to re-run coverage after writing new tests without remembering the exact command syntax.
1# Python — add to .replit:2run = "coverage run -m pytest && coverage report -m"34# Node.js — add to package.json scripts:5{6 "scripts": {7 "test": "jest",8 "coverage": "jest --coverage",9 "test:coverage": "nyc mocha"10 }11}1213# Then run from Shell:14npm run coverageExpected result: Running the coverage script produces a fresh coverage report. You can re-run it after writing new tests to see the coverage percentage increase.
Set a minimum coverage threshold
Set a minimum coverage threshold
Enforce a minimum coverage standard by configuring the tool to fail if coverage drops below a threshold. For Python, add a .coveragerc configuration file. For Node.js with nyc, add configuration to package.json. When coverage drops below the threshold, the command exits with a non-zero code, which can block deployments if included in the build command. Start with a low threshold like 60% and increase it as you add more tests.
1# Python — create .coveragerc:2[run]3source = app4omit = tests/*56[report]7fail_under = 708show_missing = True910# Node.js — add to package.json:11{12 "nyc": {13 "check-coverage": true,14 "lines": 70,15 "functions": 70,16 "branches": 60,17 "reporter": ["text", "text-summary"]18 }19}Expected result: Running coverage with a threshold configured causes the command to fail (exit code 2) if coverage is below the threshold, and succeed if it is above.
Generate an HTML coverage report for detailed review
Generate an HTML coverage report for detailed review
For a visual, file-by-file view of which lines are covered, generate an HTML report. For Python, run coverage html which creates an htmlcov directory. For Node.js, configure nyc to output HTML. Open the HTML file in Replit's Preview pane or download it for local viewing. The HTML report highlights covered lines in green and uncovered lines in red, making it easy to spot gaps at a glance.
1# Python — generate HTML report:2coverage html3# Opens htmlcov/index.html — view in Replit Preview or download45# Node.js — add HTML reporter:6{7 "nyc": {8 "reporter": ["text", "html"]9 }10}11# Run: npx nyc mocha12# Opens coverage/index.htmlExpected result: An HTML coverage report is generated in the htmlcov/ or coverage/ directory with color-coded line-by-line coverage visualization.
Complete working example
1# test_app.py — Example test file with coverage tracking2# Run with: coverage run -m pytest test_app.py && coverage report -m34import pytest56# ----- Source code to test -----7def calculate_grade(score):8 """Convert a numeric score to a letter grade."""9 if not isinstance(score, (int, float)):10 raise TypeError(f"Score must be a number, got {type(score).__name__}")11 if score < 0 or score > 100:12 raise ValueError(f"Score must be 0-100, got {score}")13 if score >= 90:14 return 'A'15 elif score >= 80:16 return 'B'17 elif score >= 70:18 return 'C'19 elif score >= 60:20 return 'D'21 else:22 return 'F'232425def calculate_average(scores):26 """Calculate the average of a list of scores."""27 if not scores:28 return 0.029 return sum(scores) / len(scores)303132def get_class_summary(students):33 """Generate a summary of class performance."""34 if not students:35 return {'count': 0, 'average': 0, 'passing': 0}3637 scores = [s['score'] for s in students]38 avg = calculate_average(scores)39 passing = sum(1 for s in students if s['score'] >= 60)4041 return {42 'count': len(students),43 'average': round(avg, 1),44 'passing': passing45 }464748# ----- Tests -----49class TestCalculateGrade:50 def test_a_grade(self):51 assert calculate_grade(95) == 'A'52 assert calculate_grade(90) == 'A'5354 def test_b_grade(self):55 assert calculate_grade(85) == 'B'5657 def test_c_grade(self):58 assert calculate_grade(75) == 'C'5960 def test_d_grade(self):61 assert calculate_grade(65) == 'D'6263 def test_f_grade(self):64 assert calculate_grade(50) == 'F'6566 def test_invalid_type(self):67 with pytest.raises(TypeError):68 calculate_grade('ninety')6970 def test_out_of_range(self):71 with pytest.raises(ValueError):72 calculate_grade(101)737475class TestCalculateAverage:76 def test_normal_list(self):77 assert calculate_average([80, 90, 70]) == 80.07879 def test_empty_list(self):80 assert calculate_average([]) == 0.0818283class TestGetClassSummary:84 def test_normal_class(self):85 students = [86 {'name': 'Alice', 'score': 90},87 {'name': 'Bob', 'score': 55},88 ]89 summary = get_class_summary(students)90 assert summary['count'] == 291 assert summary['average'] == 72.592 assert summary['passing'] == 19394 def test_empty_class(self):95 summary = get_class_summary([])96 assert summary['count'] == 0Common mistakes when tracking test coverage in Replit
Why it's a problem: Running coverage on test files instead of source files, inflating the coverage number
How to avoid: Configure coverage to only measure your source directory. In .coveragerc, set source = app and omit = tests/* to exclude test files from the report.
Why it's a problem: Aiming for 100% coverage and spending excessive time testing trivial code
How to avoid: Target 70-80% coverage for most projects. Focus on covering critical paths like data processing, authentication, and error handling rather than every getter and setter.
Why it's a problem: Generating coverage reports but never reading the Missing column to find uncovered lines
How to avoid: Always use coverage report -m (Python) or check the detailed output from jest --coverage. The Missing column tells you exactly which lines to write tests for.
Why it's a problem: Not adding coverage output directories to .gitignore, cluttering the repository
How to avoid: Add htmlcov/, coverage/, and .coverage to your .gitignore file before committing.
Best practices
- Run coverage after every batch of new tests to track progress toward your coverage goal
- Focus coverage efforts on business logic and data processing — skip boilerplate and configuration
- Use coverage report -m (Python) to see exact uncovered line numbers, not just percentages
- Set a minimum coverage threshold and increase it gradually as your test suite grows
- Add htmlcov/ and coverage/ to .gitignore to keep generated reports out of version control
- Separate your coverage script from your main run command to avoid slowing down normal development
- Write tests for error handling paths — they are the most commonly uncovered code
Still stuck?
Copy one of these prompts to get a personalized, step-by-step explanation.
I have a Python project on Replit with pytest tests. How do I set up coverage.py to measure test coverage, generate a report showing which lines are uncovered, and set a minimum coverage threshold of 70%? Give me the .coveragerc configuration and Shell commands.
Set up test coverage reporting for this project. Install coverage.py, run the existing tests with coverage tracking, generate a report showing missed lines, and create a .coveragerc file that requires at least 70% coverage and excludes the tests directory.
Frequently asked questions
No. Replit does not include a built-in coverage tool as of March 2026. You need to install coverage.py (Python) or nyc/jest (Node.js) via Shell and run them manually or through scripts.
70-80% is a practical target for most projects. Critical business logic should be at 90%+. Aiming for 100% is rarely worth the effort since it forces you to test trivial code like getters and configuration files.
Yes. Run 'coverage html' (Python) to generate an HTML report in the htmlcov directory. Open index.html in Replit's Preview pane to see color-coded line-by-line coverage with green (covered) and red (uncovered) highlighting.
Yes. Run 'npx jest --coverage' to get a coverage report without installing nyc. Jest uses istanbul internally and produces the same style of coverage report with file-by-file breakdowns.
Yes. Add a coverage check to your .replit deployment build command: build = ["sh", "-c", "coverage run -m pytest && coverage report --fail-under=70 && npm run build"]. The build will fail if coverage drops below 70%.
Yes. Ask Agent: 'Run coverage report and write tests to cover the uncovered lines in app/main.py. Focus on error handling paths and edge cases.' Agent v4 will read the coverage output and generate targeted tests.
In Python, add an omit section to .coveragerc: omit = tests/*, migrations/*, setup.py. In Node.js with nyc, add an exclude array to the nyc config in package.json: ["tests", "node_modules"].
For complex projects that need multi-environment testing, coverage aggregation across services, and CI/CD integration, the RapidDev engineering team can set up a professional testing pipeline that goes beyond what single-tool coverage tracking provides.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation