Are My Unit Tests in the Right Package?
Gergő Balogh, Tamás Gergely, Árpád Beszédes and
The software development industry has adopted written
and de facto standards for creating effective and maintainable
unit tests. Unfortunately, like any other source code artifact,
they are often written without conforming to these guidelines, or
they may evolve into such a state. In this work, we address a
specific type of issues related to unit tests. We seek to
automatically uncover violations of two fundamental rules: 1) unit
tests should exercise only the unit they were designed for, and 2)
they should follow a clear packaging convention. Our approach is
to use code coverage to investigate the dynamic behaviour of the
tests with respect to the code elements of the program, and use
this information to identify highly correlated groups of tests and
code elements (using community detection algorithm). This grouping
is then compared to the trivial grouping determined by package
structure, and any discrepancies found are treated as “bad
smells.” We report on our related measurements on a set of large
open source systems with notable unit test suites, and provide
guidelines through examples for refactoring the problematic tests.
Keywords: Code coverage,
unit testing, clusterization, package hierarchy, community
detection, test smells and refactoring.