perl – Test :: Most – 使用stacktrace报告测试失败
发布时间:2020-12-16 06:19:18 所属栏目:大数据 来源:网络整理
导读:我正在修复一个大型测试脚本( 1000行),它使用一些实用工具方法(也包括 1000行)来对各种初始数据设置执行重复测试.这有助于整合代码.但是,当测试失败时,它会报告实用程序方法内部的行号,这使得很难跟踪哪个测试失败. 当测试失败时,是否可以将 Test::Most 配置
我正在修复一个大型测试脚本(> 1000行),它使用一些实用工具方法(也包括> 1000行)来对各种初始数据设置执行重复测试.这有助于整合代码.但是,当测试失败时,它会报告实用程序方法内部的行号,这使得很难跟踪哪个测试失败.
当测试失败时,是否可以将 #!/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行,将会很有帮助. 解决方法
我不相信Test :: More基础设施提供了这样的野兽,但你真的需要堆栈跟踪吗?只要您为测试提供描述性名称,单独报告第13行就足够了.
要报告第13行而不是第17行,只需将以下内容添加到您的子网: local $Test::Builder::Level = $Test::Builder::Level + 1; 更长的例子: #!/usr/bin/env perl use strict; use warnings; use autodie; use Test::Most tests => 3; ok(1,'third test'); sub helper_sub_with_test { local $Test::Builder::Level = $Test::Builder::Level + 1; ok(0,sprintf "second test (look at line %d)",__LINE__); # Line 18 } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |