Skip to main content
RapidDev - Software Development Agency
replit-tutorial

How to track test coverage in Replit

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.

What you'll learn

  • Install and configure coverage.py for Python test coverage
  • Install and configure nyc (istanbul) for Node.js test coverage
  • Read coverage reports to identify untested lines and functions
  • Set minimum coverage thresholds to enforce testing standards
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Beginner9 min read15-20 minutesAll Replit plans (Starter, Core, Pro). Works with Python (coverage.py + pytest) and Node.js (nyc + jest/mocha).March 2026RapidDev Engineering Team
TL;DR

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

1

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.

typescript
1# For Python projects:
2pip install coverage pytest
3
4# For Node.js projects:
5npm install --save-dev nyc

Expected result: The coverage tool installs successfully. Running 'coverage --version' or 'npx nyc --version' in Shell confirms the installation.

2

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.

typescript
1# Python run tests with coverage:
2coverage run -m pytest
3coverage report
4
5# Python see which specific lines are missed:
6coverage report -m
7
8# Node.js run tests with coverage:
9npx nyc mocha
10
11# Node.js with jest (built-in coverage):
12npx jest --coverage

Expected result: A table appears in the Shell showing each source file with its coverage percentage, number of statements, and missed lines.

3

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.

typescript
1# Example Python coverage output:
2# Name Stmts Miss Cover Missing
3# --------------------------------------------------
4# app/main.py 45 12 73% 23-28, 41-45
5# app/utils.py 30 3 90% 15, 22, 29
6# app/database.py 55 20 64% 30-50
7# --------------------------------------------------
8# TOTAL 130 35 73%
9
10# Lines 23-28 in main.py and 30-50 in database.py need tests

Expected result: You can read the coverage report and identify which files and line numbers need additional tests.

4

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.

typescript
1# Python add to .replit:
2run = "coverage run -m pytest && coverage report -m"
3
4# Node.js add to package.json scripts:
5{
6 "scripts": {
7 "test": "jest",
8 "coverage": "jest --coverage",
9 "test:coverage": "nyc mocha"
10 }
11}
12
13# Then run from Shell:
14npm run coverage

Expected 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.

5

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.

typescript
1# Python create .coveragerc:
2[run]
3source = app
4omit = tests/*
5
6[report]
7fail_under = 70
8show_missing = True
9
10# 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.

6

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.

typescript
1# Python generate HTML report:
2coverage html
3# Opens htmlcov/index.html view in Replit Preview or download
4
5# Node.js add HTML reporter:
6{
7 "nyc": {
8 "reporter": ["text", "html"]
9 }
10}
11# Run: npx nyc mocha
12# Opens coverage/index.html

Expected result: An HTML coverage report is generated in the htmlcov/ or coverage/ directory with color-coded line-by-line coverage visualization.

Complete working example

test_app.py
1# test_app.py Example test file with coverage tracking
2# Run with: coverage run -m pytest test_app.py && coverage report -m
3
4import pytest
5
6# ----- 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'
23
24
25def calculate_average(scores):
26 """Calculate the average of a list of scores."""
27 if not scores:
28 return 0.0
29 return sum(scores) / len(scores)
30
31
32def get_class_summary(students):
33 """Generate a summary of class performance."""
34 if not students:
35 return {'count': 0, 'average': 0, 'passing': 0}
36
37 scores = [s['score'] for s in students]
38 avg = calculate_average(scores)
39 passing = sum(1 for s in students if s['score'] >= 60)
40
41 return {
42 'count': len(students),
43 'average': round(avg, 1),
44 'passing': passing
45 }
46
47
48# ----- Tests -----
49class TestCalculateGrade:
50 def test_a_grade(self):
51 assert calculate_grade(95) == 'A'
52 assert calculate_grade(90) == 'A'
53
54 def test_b_grade(self):
55 assert calculate_grade(85) == 'B'
56
57 def test_c_grade(self):
58 assert calculate_grade(75) == 'C'
59
60 def test_d_grade(self):
61 assert calculate_grade(65) == 'D'
62
63 def test_f_grade(self):
64 assert calculate_grade(50) == 'F'
65
66 def test_invalid_type(self):
67 with pytest.raises(TypeError):
68 calculate_grade('ninety')
69
70 def test_out_of_range(self):
71 with pytest.raises(ValueError):
72 calculate_grade(101)
73
74
75class TestCalculateAverage:
76 def test_normal_list(self):
77 assert calculate_average([80, 90, 70]) == 80.0
78
79 def test_empty_list(self):
80 assert calculate_average([]) == 0.0
81
82
83class 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'] == 2
91 assert summary['average'] == 72.5
92 assert summary['passing'] == 1
93
94 def test_empty_class(self):
95 summary = get_class_summary([])
96 assert summary['count'] == 0

Common 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.

ChatGPT Prompt

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.

Replit Prompt

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.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Need help with your project?

Our experts have built 600+ apps and can accelerate your development. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.