简体   繁体   English

我应该使用哪个Perl测试模块?

[英]Which Perl test module should I use?

There's Test::Simple , Test::More , Test::Builder (all part of the Test::Simple distribution), Test::Class , Test::Unit , Test::Moose ... Test :: SimpleTest :: MoreTest :: BuilderTest :: Simple发布的所有部分), Test :: ClassTest :: UnitTest :: Moose ......

I'm starting a new project using Moose—which module should I use for writing my tests? 我正在使用Moose开始一个新项目 - 我应该使用哪个模块来编写我的测试?

You can eliminate Test::Builder from the list for a while. 您可以暂时从列表中删除Test :: Builder。 Test::Builder is the base module that other Test:: modules are built on. Test :: Builder是构建其他Test :: modules的基础模块。 So until you want to start writing your own test modules you won't need it. 因此,除非您想开始编写自己的测试模块,否则不需要它。

I'd also ignore Test::Simple. 我也会忽略Test :: Simple。 Test::More does all that Test::Simple does - and plenty more. 测试::更多测试所有测试::简单做 - 以及更多。

Test::Class is a nice way to write unit tests in a really object oriented way. Test :: Class是一种以真正面向对象的方式编写单元测试的好方法。 I'd recommend it for complex OO-based systems. 我推荐它用于复杂的基于OO的系统。

Test::Moose is for testing various Moose-related features in your code. Test :: Moose用于测试代码中与Moose相关的各种功能。 You say that you're using Moose so it might well be useful for you. 你说你正在使用Moose,所以它可能对你有用。 It can be used in conjunction with Test::More. 它可以与Test :: More结合使用。

So my recommendation would be to start with Test::More and Test::Moose. 所以我的建议是从Test :: More和Test :: Moose开始。 But also take a look at Test::Class to see if it fits with the way that you want to write tests. 但是还要看一下Test :: Class,看看它是否适合你想要编写测试的方式。

Perl Testing: A Developers Notebook is a great introduction to this topic. Perl测试:开发人员笔记本是对该主题的精彩介绍。

In addition to davorg's excellent answer, I'd like to note that I'm still mostly using Test::More (with some help from Test-Differences , Test-WWW-Mechanize-LibXML , and other modules). 除了davorg的出色答案之外,我还要注意到我仍然主要使用Test :: More(在Test-DifferencesTest-WWW-Mechanize-LibXML和其他模块的帮助下)。 I can recommend against using Test.pm which is old and stupid, and Test::Simple, which is a small subset of the Test::More functionality. 我建议不要使用旧的和愚蠢的Test.pm,以及Test :: Simple,这是Test :: More功能的一小部分。

There are also Test::Most (an extension of Test::More), Test::Class and Test::Class::Most, which some people prefer, but I didn't take the time to learn them yet. 还有Test :: Most(Test :: More的扩展),Test :: Class和Test :: Class :: Most,有些人更喜欢,但我还没有花时间学习它们。

There's an ongoing debate about whether a plan (= tests' count) is a good thing or not . 关于计划(=测试计数)是否是好事 ,一直在争论。 Personally, I've already noticed a case in someone else's CPAN module where the count of tests was different on my system's than on them (and varied based on different versions of DBI (IIRC)) and which convinced me that the plan is a good thing. 就个人而言,我已经注意到了其他人的CPAN模块中的一个案例,其中我的系统的测试次数与他们不同(并根据不同版本的DBI(IIRC)而有所不同)并且使我确信该计划是好的事情。 As a result I've created Test-Count which is a way to count and update the assertions count based on annotations inside well-formed comments (and which supports source code in other languages besides Perl 5). 因此,我创建了Test-Count ,这是一种根据格式良好的注释中的注释来计算和更新断言计数的方法(除了Perl 5之外,它还支持其他语言中的源代码)。 I'm still supporting it, so if you need anything, give me a shout. 我仍然支持它,所以如果你需要什么,请给我一个大喊。

I'd recommend Test::Class as a basis for your test framework. 我建议将Test :: Class作为测试框架的基础。 It makes for better structured, more modular code. 它使更好的结构化,更模块化的代码。 And you can still use Test::More and other Test modules with it. 您仍然可以使用Test :: More和其他测试模块。 Also check Test::Exception. 还要检查Test :: Exception。

Others have suggested Test::Class; 其他人建议测试:: Class; I have found the following PDF overview from $foo Magazin (I didn't write it, just found it) was quite helpful for some exampled beyond what the POD documentation provides. 我发现以下来自$ foo Magazin的PDF概述 (我没有写它,只是发现它)对POD文档提供的一些示例非常有帮助。

It is not really essential for moose development. 它对于驼鹿的发展并不是必不可少的。 However, if you're into Web Development , I think Test::WWW::Selenium is becoming indespensable for testing javascript-heavy web pages and their behavior in the most common web browsers (firefox, iexplorer, googlechrome, etc.) 但是,如果您正在进行Web开发,我认为Test :: WWW :: Selenium正在成为测试javascript密集网页及其在最常见的Web浏览器中的行为(firefox,iexplorer,googlechrome等)不可或缺的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM