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
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.
Related calculators
Flash Shooting Distance
HobbyCalculate the ideal shooting distance to your subject from a flash unit's guide number, aperture and ISO.
Open calculator →Flash Aperture Calculator
HobbyCalculate the correct f-stop for flash photography from guide number, distance, and ISO. Instantly see the nearest standard f-stop and the correct distance for each aperture.
Open calculator →Lens Focal Length Calculator
HobbyEstimate the lens focal length (mm) and 35mm equivalent you need from your subject distance, real size, and sensor width.
Open calculator →Camera Angle of View Calculator
HobbyEnter a lens focal length and image sensor size to instantly calculate how wide a scene the camera captures: the horizontal, vertical, and diagonal angle of view. Includes presets for full frame, APS-C, Micro Four Thirds and more (plus custom sensor sizes) and shows the 35mm equivalent focal length too.
Open calculator →