On The Relation of Test Smells to Software Code Quality
1. On The Relation of Test Smells to
Software Code Quality
Seneca
Davide Spadini, Fabio Palomba,
Andy Zaidman, Magiel Bruntink, Alberto Bacchelli
2. @DavideSpadini ishepard
On The Relation of Test Smells to
Software Code Quality
Seneca
Davide Spadini, Fabio Palomba,
Andy Zaidman, Magiel Bruntink, Alberto Bacchelli
4. Research questions
RQ1: Are test smells associated with change/
defect proneness of test code?
RQ2: Are test smells associated with defect
proneness of production code?
5. Methodology — subject systems
10 OSS
221 Major releases
# Releases # Classes # Methods KLOC
Total 221 9 - 2,072 68 - 19,445 1 - 334
• All the metrics are calculated at method level!
6. Methodology — test smells
t
Ri
• We calculate which test methods are affected by test smells
in every release, using the detector by Bavota et al.
method is_smelly type
file1.java:m1 FALSE
file1.java:m2 TRUE Mystery Guest
file2.java:m1 TRUE
Eager Test,
Indirect Testing
file2.java:m2 FALSE
• Type of smells:
1. Mystery Guest
2. Resource Optimism
3. Eager Test
4. Assertion Roulette
5. Indirect Testing
6. Sensitive Equality
7. Methodology — change proneness of test code
• We define change proneness of a test method Ti in release Ri
as the number of times Ti changed between Ri and Ri-1.
8. Methodology — change proneness of test code
• We define change proneness of a test method Ti in release Ri
as the number of times Ti changed between Ri and Ri-1.
t
Ri-1 Ri
9. Methodology — change proneness of test code
• We define change proneness of a test method Ti in release Ri
as the number of times Ti changed between Ri and Ri-1.
t
Ri-1 Ri
#00abc45
10. Methodology — change proneness of test code
• We define change proneness of a test method Ti in release Ri
as the number of times Ti changed between Ri and Ri-1.
t
Ri-1 Ri
ATest.java
#00abc45
11. Methodology — change proneness of test code
• We define change proneness of a test method Ti in release Ri
as the number of times Ti changed between Ri and Ri-1.
t
Ri-1 Ri
ATest.java
#00abc45
ATest.java
13. Methodology — change proneness of test code
ATest.javaATest.java
method1
method2
method5
method6
method3
method1
method2
method4
14. Methodology — change proneness of test code
ATest.javaATest.java
method1
method2
method5
method6
method3
method1
method2
method4
15. Methodology — change proneness of test code
ATest.javaATest.java
method1
method2
method5
method6
method3
method1
method2
method4
sum = a + b
return sum
sum = a + b
return sum
16. Methodology — change proneness of test code
ATest.javaATest.java
method2
method5
method6
method3
method2
method4
17. Methodology — change proneness of test code
ATest.javaATest.java
method2
method5
method6
method3
method2
method4
18. Methodology — change proneness of test code
ATest.javaATest.java
method2
method5
method6
method3
method2
method4
diff = a - b
return diff
diff = b - a
return diff
19. Methodology — change proneness of test code
ATest.javaATest.java
method2
method5
method6
method3
method2
method4
diff = a - b
return diff
diff = b - a
return diff
method2 changes ++
20. Methodology — change proneness of test code
ATest.javaATest.java
method5
method6
method3
method4
21. Methodology — change proneness of test code
ATest.javaATest.java
method5
method6
method3
method4
22. Methodology — change proneness of test code
ATest.javaATest.java
method5
method6
method3
method4
cosine similarity < 0.9
23. Methodology — change proneness of test code
ATest.javaATest.java
method5
method6
method3
method4
24. Methodology — change proneness of test code
ATest.javaATest.java
method5
method6
method3
method4
cosine similarity > 0.9
method5 changes ++
25. Methodology — change proneness of test code
ATest.javaATest.java
method6
method3
26. Methodology — change proneness of test code
ATest.javaATest.java
method6
method3
cosine similarity < 0.9
27. Methodology — change proneness of test code
ATest.javaATest.java
method6
Method Added
28. Methodology — defect proneness
• We define defect proneness of a (test and production) method
Ti in release Ri as the number of defects Ti contained in Ri.
• We first obtain the bug inducing commits, and then we apply
SZZ.
t
Ri
bug#1 bug#2
30. Research questions
RQ1: Are test smells associated with change/
defect proneness of test code?
RQ1.1: To what extent are test smells
associated with the change- and defect-
proneness of test code?
31. RQ1.1: Is the co-occurrence of test smells associated with the
change- and defect-proneness of test code?
Change Proneness
1
1.47
1.31
size
overall
1.95
2.02
Conf. Int.
1.46-1.50
1.29-1.32
1.86-2.04
1.84-2.19
small
average
large
32. RQ1.1: Is the co-occurrence of test smells associated with the
change- and defect-proneness of test code?
Defect Proneness
1
1.45
1.63
3.55
2.37
1.56
1.81
Conf. Int.
1.50-1.63
2.05-2.75
2.74-4.61
size
small
average
large
C.P.
no
yes
overall
1.54-1.71
1.37-1.53
1.74-1.89
33. Research questions
RQ1: Are test smells associated with change/
defect proneness of test code?
RQ1.1: To what extent are test smells
associated with the change- and defect-
proneness of test code?
RQ1.2: Is the co-occurrence of test smells
associated with the change- and defect-
proneness of test code?
34. RQ1.2: Is the co-occurrence of test smells associated with the
change- and defect-proneness of test code?
0.0
2.5
5.0
7.5
10.0
12.5
0 1 2 3 4 5 6
Number of test smells
Numberofchanges
35. RQ1.2: Is the co-occurrence of test smells associated with the
change- and defect-proneness of test code?
0
10
20
30
40
0 1 2 3 4 5 6
Number of test smells
Numberofbugs
36. Research questions
RQ1: Are test smells associated with change/
defect proneness of test code?
RQ1.1: To what extent are test smells
associated with the change- and defect-
proneness of test code?
RQ1.2: Is the co-occurrence of test smells
associated with the change- and defect-
proneness of test code?
RQ1.3: Are certain test smell types more
associated with the change- and defect-
proneness of test code?
37. RQ1.3: Are certain test smell types more associated with the change-
and defect-proneness of test code?
0
20
40
60
Assertion Roulette Eager Test Indirect Testing Mystery Guest Sensitive Equality
Smell Type
Relationwithmaintainability
Number of changes
Number of bugs
39. Research questions
RQ2: Are test smells associated with defect
proneness of production code?
RQ2.1: To what extent are test smells
associated with the defect-proneness of
production code?
40. RQ2.1: To what extent are test smells associated with the change-
and defect- proneness of production code?
Defect Proneness
1
Conf. Int.
1.52-1.60
2.03-2.46
1.84-2.54
1.67-1.75
2.17
2.23
1.56
size
overall
small
average
large
1.71
41. RQ2.1: To what extent are test smells associated with the change-
and defect- proneness of production code?
Defect Proneness
0
5
10
Non−smelly Smelly
Type
Numberofbugs
42. Research questions
RQ2: Are test smells associated with defect
proneness of production code?
RQ2.1: To what extent are test smells
associated with the defect-proneness of
production code?
RQ2.2: Is the co-occurrence of test smells
associated with the defect-proneness of
production code?
43. RQ2.2: Is the co-occurrence of test smells associated with the defect-
proneness of production code?
0.0
2.5
5.0
7.5
10.0
0 1 2 3 4 5 6
Number of test smells
Numberofbugsintheproductionmethods
44. Research questions
RQ2: Are test smells associated with defect
proneness of production code?
RQ2.1: To what extent are test smells
associated with the defect-proneness of
production code?
RQ2.2: Is the co-occurrence of test smells
associated with the defect-proneness of
production code?
RQ2.3: Are certain test smell types more
associated with the defect-proneness of
production code?
45. RQ2.3: Are certain test smell types more associated with the defect-
proneness of production code?
0.0
2.5
5.0
7.5
10.0
Assertion Roulette Eager Test Indirect Testing Mystery Guest Sensitive Equality
Smell Type
Numberofbugsintheproductionmethods
46. SummaryTestcodeProductioncode
More change- and
defect-prone if affected
by smells
Slightly more change-
prone if affected by
more smells
More defect-prone if
exercised by test code
affected by test smells
‘Indirect Testing’ and
‘Eager Test’ smells are
more defect-prone in
the exercised
production code