TY - JOUR
T1 - Tests as Maintainable Assets Via Auto-generated Spies: A case study involving the Scala collections library's Iterator trait
AU - Läufer, Konstantin
AU - O'Sullivan, John
AU - Thiruvathukal, George K.
N1 - Konstantin Läufer, John O’Sullivan, and George K. Thiruvathukal. 2019. Tests as Maintainable Assets Via Auto-generated Spies. In Proceedings of Tenth ACM SIGPLAN Scala Symposium, London, United Kingdom, July 17, 2019 (Scala ’19),6 pages, DOI: 10.1145/3337932.3338814
PY - 2019/7/17
Y1 - 2019/7/17
N2 - In testing stateful abstractions, it is often necessary to record interactions, such as method invocations, and express assertions over these interactions. Following the Test Spy design pattern, we can reify such interactions programmatically through additional mutable state. Alternatively, a mocking framework, such as Mockito, can automatically generate test spies that allow us to record the interactions and express our expectations in a declarative domain-specific language. According to our study of the test code for Scala’s Iterator trait, the latter approach can lead to a significant reduction of test code complexity in terms of metrics such as code size (in some cases over 70% smaller), cyclomatic complexity, and amount of additional mutable state required. In this tools paper, we argue that the resulting test code is not only more maintainable, readable, and intentional, but also a better stylistic match for the Scala community than manually implemented, explicitly stateful test spies.
AB - In testing stateful abstractions, it is often necessary to record interactions, such as method invocations, and express assertions over these interactions. Following the Test Spy design pattern, we can reify such interactions programmatically through additional mutable state. Alternatively, a mocking framework, such as Mockito, can automatically generate test spies that allow us to record the interactions and express our expectations in a declarative domain-specific language. According to our study of the test code for Scala’s Iterator trait, the latter approach can lead to a significant reduction of test code complexity in terms of metrics such as code size (in some cases over 70% smaller), cyclomatic complexity, and amount of additional mutable state required. In this tools paper, we argue that the resulting test code is not only more maintainable, readable, and intentional, but also a better stylistic match for the Scala community than manually implemented, explicitly stateful test spies.
KW - Scala
KW - testing
KW - test spies
KW - software engineering
KW - maintainability
UR - https://ecommons.luc.edu/cs_facpubs/230
U2 - 10.1145/3337932.3338814
DO - 10.1145/3337932.3338814
M3 - Article
JO - Computer Science: Faculty Publications and Other Works
JF - Computer Science: Faculty Publications and Other Works
ER -