keisoku

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 lines12,000 lines
Source size12.00 KLOC
Test cases320
Bugs found48
Test density26.67 /KLOC
Bug density4.00 /KLOC
Bugs found per test case0.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.