如何分离不同种类的 Perl 测试,这样我就不必全部运行它们? [英] How can I separate different sorts of Perl tests so I don't have to run them all?

查看:69
本文介绍了如何分离不同种类的 Perl 测试,这样我就不必全部运行它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到在 Perl 中的习惯是将所有测试放入 t 目录中.您如何将单元测试与功能测试分开?或者,为了使问题更简单、更明显,您如何将快速运行的测试与不快速运行的测试分开?当所有测试一起运行时,测试时间太长,无法在开发中常规使用,这是一种遗憾.

I noticed that in Perl the custom is to stick all tests into the t directory. How do you separate the unit test from the functional ones? Or, to make the question simpler and more obvious, how do you separate the tests that run quickly from the ones that do not? When all the tests run together the testing takes too long to be routinely used in development, which is a pity.

我想我可以设置一些环境变量,比如 QUICK_TEST 并根据它的值跳过长时间的测试.您是否将单元测试和功能测试分开?如何?(这不是民意调查 - 我只是想也许有一些惯用的解决方案.)

I figured I could set some environment variable like QUICK_TEST and skip the long tests according to its value. Do you separate unit and functional tests? How? (This is not meant to be a poll – I just thought maybe there’s some idiomatic solution.)

更新:到目前为止,我已经做到了:

Update: So far I have come to this:

package Test::Slow;

use strict;
use Test::More;

BEGIN {
    plan(skip_all => 'Slow test.') if $ENV{QUICK_TEST};
}

1;

并在附近的 .t 文件中:

And in a nearby .t file:

# This is a slow test not meant
# to run frequently.
use Test::Slow;
use Test::More;

它似乎工作得很好.

附言现在可作为 Test::Slow 在 CPAN 上使用.

P.S. Now available as Test::Slow on CPAN.

推荐答案

您当然可以将测试划分为 t 下的子目录,您可以使用任何您想要的分类方案.如果您使用环境变量,我建议将默认值(如果未设置该变量)设为运行所有测试.我见过 t/只包含在开发中经常运行的测试而其他测试放在不同目录下的情况(例如 t-selenium/).

You can certainly divide tests into subdirectories under t, with whatever categorization scheme you want. If you use an environment variable, I'd recommend making the default (if the variable is not set) be to run all tests. I've seen situations where t/ contains just the tests that would be routinely run in development and other tests are put under a different directory (e.g. t-selenium/).

我认为这归结为一致性比您做出的选择更重要;如果您保持一致,几乎任何事情都会奏效.

I think it comes down to consistency being more important than which choice you make; just about anything will work if you are consistent.

这篇关于如何分离不同种类的 Perl 测试,这样我就不必全部运行它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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