通过自动生成的Spies将测试作为维护资产:涉及Scala集合库的Iterator特性的案例研究
Tests as Maintainable Assets Via Auto-generated Spies: A case study involving the Scala collections library's Iterator trait
摘要:
在测试有状态抽象时,经常需要记录交互,比如方法调用,并在这些交互上表达断言。遵循TestSpy设计模式,我们可以通过额外的可变状态以编程方式具体化这样的交互。或者,一个mocking框架,比如Mockito,可以自动生成测试间谍,让我们记录交互,并用声明性的领域特定语言表达我们的期望。根据我们对Scala的Iterator trait测试代码的研究,后一种方法可以显著降低测试代码的复杂性,如代码大小(在某些情况下减少70%以上),圈复杂性和所需的额外可变状态量。在这篇工具论文中,我们认为生成的测试代码不仅更具可维护性,可读性和意图,而且比手动实现的显式状态测试间谍更适合Scala社区。
英文摘要:
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.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。