Test Density & Bug Density Calculator
Calculate bug density (bugs per KLOC), test density, and bugs found per test case from your source size, test case count, and detected bugs. A quick way to build software quality metrics.
Input
Size unit
lines
Result
Bug density (bugs / KLOC)
4.00/KLOC
Test density
26.7 /KLOC
Bug detection rate
15.0 %
Size
12.00 KLOC
| Source lines | 12,000 lines |
| Source size | 12.00 KLOC |
| Test cases | 320 |
| Bugs found | 48 |
| Test density | 26.67 /KLOC |
| Bug density | 4.00 /KLOC |
| Bugs found per test case | 0.150 /test |
How it works
- Bug density is calculated as 'bugs found ÷ source size (KLOC)' and shows how many defects were found per 1,000 lines (1 KLOC). A lower value generally suggests cleaner code, but note that it can look artificially low when test coverage is weak.
- Test density is 'number of test cases ÷ KLOC' and indicates how many tests you prepared per 1,000 lines. It serves as a guide for judging whether testing is sufficient relative to the codebase size.
- The bug detection rate (bugs found per test case) is calculated as 'bugs found ÷ number of test cases'. A value that is too high may signal quality issues, while a value that is too low may indicate biased test coverage.
- You can switch the size unit between 'lines' and 'KLOC (thousand lines)'. Aligning your counting rules across the project—such as whether comments and blank lines are included—makes comparisons easier.
- These figures are only relative guides. Appropriate values vary widely by language, development phase, and testing strategy, so we recommend establishing your own baseline by comparing against past or similar projects.
Reviews
Tell us what you think of this calculator.
Write a review
Found an incorrect result or a problem? Turn this on to report it.
- Home
Test Density & Bug Density Calculator