只想知道是否可以强制casperjs仅将失败的测试输出到控制台。 有没有人试过这样做?
谢谢
答案 0 :(得分:1)
由于您正在运行CasperJS测试环境,因此可以在运行CasperJS时添加--concise
option:
casperjs test --concise yourTest.js
这会隐藏所有断言日志,但不会隐藏FAIL的其他信息:
Test file: test20_only_show_fail.js # type: assert # file: test20_only_show_fail.js:8 # code: test.assert(false, "false"); # subject: false # type: assert # file: test20_only_show_fail.js:13 # code: test.assert(false, "false"); # subject: false FAIL 3 tests executed in 0.027s, 1 passed, 2 failed, 0 dubious, 0 skipped.
但现在你无法轻易区分它们。您可以在测试文件的前面添加一个事件监听器,并让它打印一些有用的东西:
casper.test.on("fail", function(failure) {
this.casper.echo("FAIL " + failure.message);
});
这会生成附加信息之后的FAIL行:
Test file: test20_only_show_fail.js # type: assert # file: test20_only_show_fail.js:7 # code: test.assert(false, "false"); # subject: false FAIL false # type: assert # file: test20_only_show_fail.js:12 # code: test.assert(false, "false"); # subject: false FAIL false FAIL 3 tests executed in 0.028s, 1 passed, 2 failed, 0 dubious, 0 skipped.
这是测试文件(test20_only_show_fail.js)供参考:
casper.test.on("fail", function(failure) {
this.casper.echo("FAIL " + failure.message);
});
casper.test.begin('fail test', function(test) {
test.assert(true, "true");
test.assert(false, "false");
test.assert(true, "true (2)");
});
casper.test.begin('error test', function(test) {
test.assert(false, "false");
});