Perl 的首选单元测试框架是什么? [英] What is the preferred unit testing framework for Perl?

查看:42
本文介绍了Perl 的首选单元测试框架是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Perl 有点陌生,想知道是否有首选的单元测试框架?

I'm sort of new to Perl and I'm wondering if there a prefered unit testing framework?

Google 向我展示了一些不错的结果,但由于我是新手,我不知道社区内是否有明确的偏好.

Google is showing me some nice results, but since I'm new to this, I don't know if there is a clear preference within the community.

推荐答案

Perl 附带了大量出色的测试工具!Perl 核心对其进行了数以万计的自动检查,并且在大多数情况下,它们都使用这些标准 Perl 框架.它们都使用 TAP 联系在一起 - 测试任何协议.

Perl has a MASSIVE set of great testing tools that come with it! The Perl core has several tens of thousands of automated checks for it, and for the most part they all use use these standard Perl frameworks. They're all tied together using TAP - the Test Anything Protocol.

在 Perl 中创建 TAP 测试的标准方法是使用 Test::More 包系列,包括用于入门的 Test::Simple.这是一个简单的例子:

The standard way of creating TAP tests in Perl is using the Test::More family of packages, including Test::Simple for getting started. Here's a quick example:

use 5.012;
use warnings;

use Test::More tests => 3;

my $foo = 5;
my $bar = 6;

ok $foo == 5, 'Foo was assigned 5.';
ok $bar == 6, 'Bar was assigned 6.';
ok $foo + $bar == 11, 'Addition works correctly.';

输出将是:

ok 1 - Foo was assigned 5.
ok 2 - Bar was assigned 6.
ok 3 - Addition works correctly.

基本上,要开始,您需要做的就是传递一个布尔值和一个字符串,说明应该发生什么!

Essentially, to get started, all you need to do is put pass a boolean value and a string explaining what should occur!

一旦你通过了这一步,Test::More 有大量其他函数可以让测试其他东西更容易(字符串、正则表达式比较、深层结构比较),还有 Test::Harness 后端,可让您一起测试大量单独的测试脚本.

Once you get past that step, Test::More has a large number of other functions to make testing other things easier (string, regex compares, deep structure compares) and there's the Test::Harness back end that will let you test large groups of individual test scripts together.

最重要的是,正如 Schwern 指出的那样,几乎所有现代 Test:: 模块协同工作.这意味着您可以使用 Test::Class(如Markus 指出)以及 rjh答案.事实上,因为Test::Builder——Test的工具::More 和其他构建于(目前由 Schwern 维护...感谢 Schwern!)--如果需要,您可以从头开始构建您自己的测试子例程,该子例程将与所有其他测试框架一起使用.仅此一点就使 Perl 的 TAP 系统成为我认为最好的系统之一:一切都可以协同工作,每个人都使用相同的工具,您只需很少的额外工作就可以添加到框架中以满足您的需求.

On top of that, as Schwern pointed out, almost all of the modern Test:: modules work together. That means you can use Test::Class (as pointed out by Markus) with all of the great modules listed in rjh's answer. In fact, because Test::Builder--the tool that Test::More and others are built on (and currently maintained by Schwern...thanks Schwern!)--you can, if needed, build your OWN test subroutines from the ground up that will work with all the other test frameworks. That alone makes Perl's TAP system one of the nicest out there in my opinion: everything works together, everyone uses the same tool, and you can add on to the framework to suit your needs with very little additional work.

这篇关于Perl 的首选单元测试框架是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆