Defect density is nothing but the no. of buge found for N lines of code.
It is the ratio of defects to size.The comman ration is the no. of defects per thousand lines of code(KLOC).function points(FP) or some other metric code of size,or no. of classes.
Bug Density = No. of defects/no. of lines of code or FP
There are some use of A/A+B. if A/A+B is close to 1 then you are making good testing. But lets say if it is 0.9 then for every 9 defect you found, you miss 1 defect which goes to customer and customer founds it, which is not a good ratio.
I am using this measure and putting goal of making B/A+B <0.03 for regular projects
B/A+B<0.001 for mission critical projects
Of course this does not mean that "there are not any defects left" but If I can not found it and customers also can not found it then for me it does not exists. This also help me to show the testing team success to management.
Defect density is a measure of the total known defects divided by the size of the
software entity being measured.
Number of Known Defects /Size
Size is measured as LOC or Number of Function Points.
Defect Density is used to compare the relative number of defects in various software components. This helps identify candidates for additional inspection or testing or for possible reengineering or replacement. Identifying defect prone components allows the concentration of limited resources into areas with the highest potential return on the investment.
What are various ways of calculating defect density?
The formula itself is simple: Density = Total Defects Found / Size
if we see defect density at granular level say Codesize of a particular functionality X in a application Y along with number of files, then we may draw some good observations like
Taking an example here:- Lets say we have an application ABC, which have three functionality/modules A, B and C.
Code files for A =10 and KLOC=5k
Code files for B =5 and KLOC=1k
Code files for C =1 and KLOC=25k
Bugs found in A=40, B=50, and C=5
Defect density = Total number of defects/LOC (lines of code)
Defect density = Total number of defects/Size of the project
Size of Project can be Function points, feature points, use cases, KLOC etc
Perhaps i am diverting the attention a bit here but KLOC is an ambiguous mesaure and since KLOC is an ambiguous measure i think FPA can be best use to measure the size. If FP is the best measure of size then i think N/F
N=Number of Defects
F=Number of Function Points is most accurate mesaure.