EUnit: Erlang的轻量级单元测试框架

Richard Carlsson, Mickaël Rémond
{"title":"EUnit: Erlang的轻量级单元测试框架","authors":"Richard Carlsson, Mickaël Rémond","doi":"10.1145/1159789.1159791","DOIUrl":null,"url":null,"abstract":"In recent years, agile development methods have become increasingly popular, and although few people seem willing to go all the way with Extreme Programming, it seems that there is a general consensus today that test-driven development with unit testing is a Good Thing. However, this requires that tests are easy to write, since programmers are generally lazy, and that running the tests is easy and quick and the test results are presented in a concise manner, to make the feedback loop as short as possible. Failing this, it is likely that testing will not be extensively used during development.The concept of a lightweight unit testing framework that fulfils these goals, tailored to a particular programming language, was popularized by the JUnit framework for Java, written by Kent Beck and Erich Gamma. This was based on an earlier framework for Smalltalk called SUnit, by Kent Beck. The ideas in JUnit are easily transferred to any other object-oriented language, and today variants have been written for many different programming languages.We will here present our adaptation of these ideas to Erlang. The EUnit framework provides the usual features of such frameworks: writing tests is very easy indeed, and so is running them. Like most other similar frameworks, we rely on program introspection and naming conventions to reduce the amount of coding necessary to write tests. However, there are also some unusual aspects. Since Erlang is functional, rather than object oriented, it is not possible to use inheritance to provide basic test functionality, nor to use object instantiation to handle things like setup/teardown of contexts for tests. Instead, we base our system on a \"language\" for describing sets of tests, using mainly lists, tuples, and lambda expressions. We also make rather heavy use of preprocessor macros to allow more compact and readable notation. Because test descriptions are data, they can be easily combined, abstracted over, or even be generated on the fly. Lambda expressions allow subtests to be instantiated with setup/teardown contexts.Furthermore, the parallel and distributed nature of the Erlang language on one hand provides a challenge, but on the other hand gives us enormous power and flexibility. For instance, it is trivial to express in our test description language that a set of tests should be executed by a separate process, or on a specific machine, or all in parallel, or even as a number of subsets of parallel tests, with each subset running on a separate machine. Apart from providing easy distributed job control, this allows us to write unit tests that test the behaviour of parallel and distributed programs, something which otherwise tends to require so much coding for each test as to be impractical.Although EUnit is still under development, we feel that it has great potential, and that it uses some novel ideas that could be used to implement similar frameworks in other functional languages. EUnit is free software under the GNU Lesser General Public License. It has not yet been publicly released as of this writing.","PeriodicalId":140676,"journal":{"name":"Erlang Workshop","volume":"1 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2006-09-16","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"24","resultStr":"{\"title\":\"EUnit: a lightweight unit testing framework for Erlang\",\"authors\":\"Richard Carlsson, Mickaël Rémond\",\"doi\":\"10.1145/1159789.1159791\",\"DOIUrl\":null,\"url\":null,\"abstract\":\"In recent years, agile development methods have become increasingly popular, and although few people seem willing to go all the way with Extreme Programming, it seems that there is a general consensus today that test-driven development with unit testing is a Good Thing. However, this requires that tests are easy to write, since programmers are generally lazy, and that running the tests is easy and quick and the test results are presented in a concise manner, to make the feedback loop as short as possible. Failing this, it is likely that testing will not be extensively used during development.The concept of a lightweight unit testing framework that fulfils these goals, tailored to a particular programming language, was popularized by the JUnit framework for Java, written by Kent Beck and Erich Gamma. This was based on an earlier framework for Smalltalk called SUnit, by Kent Beck. The ideas in JUnit are easily transferred to any other object-oriented language, and today variants have been written for many different programming languages.We will here present our adaptation of these ideas to Erlang. The EUnit framework provides the usual features of such frameworks: writing tests is very easy indeed, and so is running them. Like most other similar frameworks, we rely on program introspection and naming conventions to reduce the amount of coding necessary to write tests. However, there are also some unusual aspects. Since Erlang is functional, rather than object oriented, it is not possible to use inheritance to provide basic test functionality, nor to use object instantiation to handle things like setup/teardown of contexts for tests. Instead, we base our system on a \\\"language\\\" for describing sets of tests, using mainly lists, tuples, and lambda expressions. We also make rather heavy use of preprocessor macros to allow more compact and readable notation. Because test descriptions are data, they can be easily combined, abstracted over, or even be generated on the fly. Lambda expressions allow subtests to be instantiated with setup/teardown contexts.Furthermore, the parallel and distributed nature of the Erlang language on one hand provides a challenge, but on the other hand gives us enormous power and flexibility. For instance, it is trivial to express in our test description language that a set of tests should be executed by a separate process, or on a specific machine, or all in parallel, or even as a number of subsets of parallel tests, with each subset running on a separate machine. Apart from providing easy distributed job control, this allows us to write unit tests that test the behaviour of parallel and distributed programs, something which otherwise tends to require so much coding for each test as to be impractical.Although EUnit is still under development, we feel that it has great potential, and that it uses some novel ideas that could be used to implement similar frameworks in other functional languages. EUnit is free software under the GNU Lesser General Public License. It has not yet been publicly released as of this writing.\",\"PeriodicalId\":140676,\"journal\":{\"name\":\"Erlang Workshop\",\"volume\":\"1 1\",\"pages\":\"0\"},\"PeriodicalIF\":0.0000,\"publicationDate\":\"2006-09-16\",\"publicationTypes\":\"Journal Article\",\"fieldsOfStudy\":null,\"isOpenAccess\":false,\"openAccessPdf\":\"\",\"citationCount\":\"24\",\"resultStr\":null,\"platform\":\"Semanticscholar\",\"paperid\":null,\"PeriodicalName\":\"Erlang Workshop\",\"FirstCategoryId\":\"1085\",\"ListUrlMain\":\"https://doi.org/10.1145/1159789.1159791\",\"RegionNum\":0,\"RegionCategory\":null,\"ArticlePicture\":[],\"TitleCN\":null,\"AbstractTextCN\":null,\"PMCID\":null,\"EPubDate\":\"\",\"PubModel\":\"\",\"JCR\":\"\",\"JCRName\":\"\",\"Score\":null,\"Total\":0}","platform":"Semanticscholar","paperid":null,"PeriodicalName":"Erlang Workshop","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1145/1159789.1159791","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 24

摘要

近年来,敏捷开发方法变得越来越流行,尽管很少有人愿意使用极限编程,但今天似乎有一个普遍的共识,即带有单元测试的测试驱动开发是一件好事。然而,这要求测试易于编写,因为程序员通常是懒惰的,并且运行测试是简单和快速的,测试结果以简洁的方式呈现,以使反馈循环尽可能短。如果做不到这一点,测试很可能不会在开发过程中被广泛使用。实现这些目标的轻量级单元测试框架的概念,为特定的编程语言量身定制,是由Kent Beck和Erich Gamma编写的Java JUnit框架推广的。这是基于Kent Beck为Smalltalk编写的名为SUnit的早期框架。JUnit中的思想很容易转移到任何其他面向对象的语言中,今天已经为许多不同的编程语言编写了变体。在这里,我们将介绍如何将这些思想应用到Erlang中。EUnit框架提供了此类框架的常见特性:编写测试非常简单,运行测试也非常简单。像大多数其他类似框架一样,我们依靠程序自省和命名约定来减少编写测试所需的代码量。然而,也有一些不寻常的方面。由于Erlang是函数式的,而不是面向对象的,所以不可能使用继承来提供基本的测试功能,也不可能使用对象实例化来处理诸如设置/拆除测试上下文之类的事情。相反,我们将系统建立在描述测试集的“语言”上,主要使用列表、元组和lambda表达式。我们还大量使用预处理器宏来实现更紧凑和可读的符号。因为测试描述是数据,所以它们可以很容易地组合、抽象,甚至可以动态生成。Lambda表达式允许使用setup/teardown上下文实例化子测试。此外,Erlang语言的并行和分布式特性一方面给我们带来了挑战,但另一方面又为我们提供了巨大的能力和灵活性。例如,在我们的测试描述语言中表达一组测试应该由单独的进程执行,或者在特定的机器上执行,或者全部并行执行,甚至作为并行测试的许多子集执行,每个子集在单独的机器上运行,这是微不足道的。除了提供简单的分布式作业控制之外,它还允许我们编写单元测试来测试并行和分布式程序的行为,否则每个测试往往需要大量的编码,这是不切实际的。尽管EUnit仍在开发中,但我们觉得它有很大的潜力,而且它使用了一些新颖的想法,可以用来在其他函数式语言中实现类似的框架。EUnit是GNU较宽松通用公共许可证下的自由软件。在撰写本文时,它尚未公开发布。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
EUnit: a lightweight unit testing framework for Erlang
In recent years, agile development methods have become increasingly popular, and although few people seem willing to go all the way with Extreme Programming, it seems that there is a general consensus today that test-driven development with unit testing is a Good Thing. However, this requires that tests are easy to write, since programmers are generally lazy, and that running the tests is easy and quick and the test results are presented in a concise manner, to make the feedback loop as short as possible. Failing this, it is likely that testing will not be extensively used during development.The concept of a lightweight unit testing framework that fulfils these goals, tailored to a particular programming language, was popularized by the JUnit framework for Java, written by Kent Beck and Erich Gamma. This was based on an earlier framework for Smalltalk called SUnit, by Kent Beck. The ideas in JUnit are easily transferred to any other object-oriented language, and today variants have been written for many different programming languages.We will here present our adaptation of these ideas to Erlang. The EUnit framework provides the usual features of such frameworks: writing tests is very easy indeed, and so is running them. Like most other similar frameworks, we rely on program introspection and naming conventions to reduce the amount of coding necessary to write tests. However, there are also some unusual aspects. Since Erlang is functional, rather than object oriented, it is not possible to use inheritance to provide basic test functionality, nor to use object instantiation to handle things like setup/teardown of contexts for tests. Instead, we base our system on a "language" for describing sets of tests, using mainly lists, tuples, and lambda expressions. We also make rather heavy use of preprocessor macros to allow more compact and readable notation. Because test descriptions are data, they can be easily combined, abstracted over, or even be generated on the fly. Lambda expressions allow subtests to be instantiated with setup/teardown contexts.Furthermore, the parallel and distributed nature of the Erlang language on one hand provides a challenge, but on the other hand gives us enormous power and flexibility. For instance, it is trivial to express in our test description language that a set of tests should be executed by a separate process, or on a specific machine, or all in parallel, or even as a number of subsets of parallel tests, with each subset running on a separate machine. Apart from providing easy distributed job control, this allows us to write unit tests that test the behaviour of parallel and distributed programs, something which otherwise tends to require so much coding for each test as to be impractical.Although EUnit is still under development, we feel that it has great potential, and that it uses some novel ideas that could be used to implement similar frameworks in other functional languages. EUnit is free software under the GNU Lesser General Public License. It has not yet been publicly released as of this writing.
求助全文
通过发布文献求助,成功后即可免费获取论文全文。 去求助
来源期刊
自引率
0.00%
发文量
0
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
确定
请完成安全验证×
copy
已复制链接
快去分享给好友吧!
我知道了
右上角分享
点击右上角分享
0
联系我们:info@booksci.cn Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。 Copyright © 2023 布克学术 All rights reserved.
京ICP备2023020795号-1
ghs 京公网安备 11010802042870号
Book学术文献互助
Book学术文献互助群
群 号:604180095
Book学术官方微信