Tests as maintainable assets via auto-generated spies: a case study involving the scala collections library's iterator trait

Konstantin Läufer, John O'Sullivan, G. Thiruvathukal
{"title":"Tests as maintainable assets via auto-generated spies: a case study involving the scala collections library's iterator trait","authors":"Konstantin Läufer, John O'Sullivan, G. Thiruvathukal","doi":"10.1145/3337932.3338814","DOIUrl":null,"url":null,"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.","PeriodicalId":436969,"journal":{"name":"Proceedings of the Tenth ACM SIGPLAN Symposium on Scala","volume":"289 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2019-07-17","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"1","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"Proceedings of the Tenth ACM SIGPLAN Symposium on Scala","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1145/3337932.3338814","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 1

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.
查看原文
分享 分享
微信好友 朋友圈 QQ好友 复制链接
本刊更多论文
通过自动生成的间谍将测试作为可维护的资产:涉及scala集合库的迭代器特性的案例研究
在测试有状态抽象时,通常需要记录交互,例如方法调用,并在这些交互上表达断言。按照Test Spy设计模式,我们可以通过额外的可变状态以编程方式实现这样的交互。另外,mock框架,例如Mockito,可以自动生成测试间谍,允许我们记录交互并用声明性领域特定语言表达我们的期望。根据我们对Scala的Iterator特性的测试代码的研究,后一种方法可以显著降低测试代码的复杂性,比如代码大小(在某些情况下减少了70%以上)、圈复杂度和所需的额外可变状态的数量。在这篇关于工具的文章中,我们认为最终的测试代码不仅更具可维护性、可读性和目的性,而且比手动实现的显式有状态测试间谍更适合Scala社区的风格。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 去求助
来源期刊
自引率
0.00%
发文量
0
期刊最新文献
Tests as maintainable assets via auto-generated spies: a case study involving the scala collections library's iterator trait Dependent object types with implicit functions SoCRATES: Scala radar for test smells Towards improved GADT reasoning in Scala Effpi
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
现在去查看 取消
×
提示
确定
0
微信
客服QQ
Book学术公众号 扫码关注我们
反馈
×
意见反馈
请填写您的意见或建议
请填写您的手机或邮箱
已复制链接
已复制链接
快去分享给好友吧!
我知道了
×
扫码分享
扫码分享
Book学术官方微信
Book学术文献互助
Book学术文献互助群
群 号:481959085
Book学术
文献互助 智能选刊 最新文献 互助须知 联系我们:info@booksci.cn
Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。
Copyright © 2023 Book学术 All rights reserved.
ghs 京公网安备 11010802042870号 京ICP备2023020795号-1