Tests as Maintainable Assets via Auto-Generated Spies: a Case Study Involving the Scala Collections Library's Iterator Trait
Item
Title
Tests as Maintainable Assets via Auto-Generated Spies: a Case Study Involving the Scala Collections Library's Iterator Trait
Loyola Faculty Contributor
Konstantin Läufer
Link
List of Authors
Konstantin Läufer; John O'Sullivan; George K Thiruvathukal
Abstract
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.
Date
17-Jul-19
Publication Title
Scala '19: Proceedings of the Tenth ACM SIGPLAN Symposium on Scala
Publisher
Association for Computing Machinery
Identifier
https://doi.org/10.1145/3337932.3338814
Bibliographic Citation
Konstantin Läufer, John O'Sullivan, and George K. Thiruvathukal. 2019. Tests as maintainable assets via auto-generated spies: a case study involving the Scala collections library's iterator trait. In Proceedings of the Tenth ACM SIGPLAN Symposium on Scala (Scala '19). Association for Computing Machinery, New York, NY, USA, 17–21. DOI:10.1145/3337932.3338814