【发布时间】:2015-01-04 00:57:54
【问题描述】:
我正在修复一个大型测试脚本(> 1000 行),它使用一些实用方法(也 > 1000 行)对各种初始数据设置执行重复测试。这有助于整合代码。但是,当测试失败时,它会报告实用方法内部的行号,因此很难追踪哪个测试失败。
是否可以将Test::Most 配置为在测试失败时提供堆栈跟踪而不是仅提供单个行号?
#!/usr/bin/env perl
use strict;
use warnings;
use autodie;
use Test::Most tests => 3;
ok(1, 'first test');
note "The following includes a failed test, but a stack trace would be more helpful";
helper_sub_with_test(); # Line 13
ok(1, 'third test');
sub helper_sub_with_test {
ok(0, "second test"); # Line 17
}
输出:
$ perl scratch.pl
1..3
ok 1 - first test
# The following includes a failed test, but a stack trace would be more helpful
not ok 2 - second test
# Failed test 'second test'
# at scratch.pl line 17.
ok 3 - third test
# Looks like you failed 1 test of 3.
如您所见,如果失败的测试同时报告了第 17 行和第 13 行,这将有助于对实用程序方法进行多次调用。
【问题讨论】:
-
use Carp::Always? -
@mob,Test::Builder 不会通过
warn/die输出其诊断信息。它只是对 STDERR 执行print,所以 Carp::Always 无法钩住它。 -
@Miller 而不是堆栈跟踪,请考虑使用
is、like或is_deeply而不仅仅是ok提供更多诊断信息。使用explain可以提供更多诊断信息。成语ok $something || explain $complex_data很有用。如果您发布实际帮助函数的样子,我们或许可以对其进行改进。 -
@Schwern 我正在使用一个非常大的测试套件(数百个测试),这个特殊的实用程序模块有超过一千行代码。一些测试已经开始失败,因为我们已经弃用了一些代码,所以我试图快速评估发生了什么问题,而不必重构整个测试设置,这承认可以使用一些工作。这就是为什么我一直在寻找一种方法来获取 Test::More 以提供更多信息,而不必手动编辑每个测试来执行
ok $something or diag Carp::longmess $stuff
标签: perl