通过命令行运行空手道时,是否可以输出漂亮的报告?
运行此:
java -jar karate-0.9.1.jar tests/*.feature
产生这个:
15:32:56.363 [main] INFO com.intuit.karate.netty.Main - Karate
version: 0.9.1
15:32:56.466 [main] INFO com.intuit.karate.Runner - Karate version:
0.9.1
15:32:56.868 [ForkJoinPool-1-worker-1] WARN com.intuit.karate -
skipping bootstrap configuration: could not find or read file:
classpath:karate-config.js
15:32:57.065 [ForkJoinPool-1-worker-1] DEBUG com.intuit.karate -
request:
1 > GET http://localhost:8080/ping
1 > Accept-Encoding: gzip,deflate
1 > Connection: Keep-Alive
1 > Host: localhost:8080
1 > User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_191)
15:32:57.114 [ForkJoinPool-1-worker-1] DEBUG com.intuit.karate -
response time in milliseconds: 47.35
1 < 200
1 < Content-Length: 18
1 < Content-Type: application/json; charset=utf-8
1 < Date: Wed, 16 Jan 2019 15:32:57 GMT
1 < X-Request-Id: ffa3630d-19a3-11e9-bbab-0242ac180007
{"message":"pong"}
15:32:57.138 [ForkJoinPool-1-worker-1] ERROR com.intuit.karate -
assertion failed: path: $.message, actual: 'pong', expected:
'pong2', reason: not equal
15:32:57.163 [ForkJoinPool-1-worker-1] INFO
com.intuit.karate.Runner - <<fail>> feature 1 of 1:
tests/ping.feature
---------------------------------------------------------
feature: tests/ping.feature
report: target/tests.ping.json
scenarios: 1 | passed: 0 | failed: 1 | time: 0.2609
---------------------------------------------------------
Karate version: 0.9.1
======================================================
elapsed: 0.70 | threads: 1 | thread time: 0.26
features: 1 | ignored: 0 | efficiency: 0.37
scenarios: 1 | passed: 0 | failed: 1
======================================================
failed features:
tests.ping: ping.feature:8 - path: $.message, actual: 'pong',
expected: 'pong2', reason: not equal
Exception in thread "main" picocli.CommandLine$ExecutionException:
there are test failures
at
com.intuit.karate.netty.Main$1.handleExecutionException
(Main.java:118)
at picocli.CommandLine.parseWithHandlers(CommandLine.java:1157)
at com.intuit.karate.netty.Main.main(Main.java:124)
更多是日志而不是报告。
我知道Karate会生成一个漂亮的HTML报告,但是当您想快速确定哪些测试失败时,这在CI管道中并没有什么用。
类似的东西会很棒:
Feature:
Scenario:
Before hook
Given this step passes
AfterStep hook
After hook
error (RuntimeError)
./features/step_definitions/output_steps.rb:11:in `After'
Failing Scenarios:
cucumber features/test.feature:2
1 scenario (1 failed)
1 step (1 passed)
答案 0 :(得分:1)
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 6.165 sec <<< FAILURE!
[1:6] get all characters([getAllPeople]) Time elapsed: 0.007 sec <<< ERROR!
com.intuit.karate.exception.KarateException: getAllPeople.feature:12 - path: $[0].birth_year, actual: '19BBY', expected: '#number', reason: not a number
at ✽.And match each $.results[*] == char (getAllPeople.feature:12)
[1:6] get the first character([getFirstCharacter]) Time elapsed: 0.001 sec <<< ERROR!
com.intuit.karate.exception.KarateException: getFirstCharacter.feature:12 - path: $.birth_year, actual: '19BBY', expected: '19BB', reason: not equal
at ✽.And match $ == firstChar (getFirstCharacter.feature:12)
Results :
Tests in error:
[1:6] get all characters([getAllPeople]): getAllPeople.feature:12 - path: $[0].birth_year, actual: '19BBY', expected: '#number', reason: not a number
[1:6] get the first character([getFirstCharacter]): getFirstCharacter.feature:12 - path: $.birth_year, actual: '19BBY', expected: '19BB', reason: not equal
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.588 s
[INFO] Finished at: 2019-01-16T17:05:13+01:00
[INFO] Final Memory: 19M/237M
我相信通过此显示,可以轻松快速地确定哪些测试失败以及原因。由于Java异常,在您的示例中比较难,但是与许多CLI报告相比,空手道的结果实际上更易于阅读。
答案 1 :(得分:1)
这是我的建议,如果您确实感觉需要更整洁的报告,请编写一个小型实用程序,该实用程序将处理*.json
文件夹中的所有target/cucumber-html-reports
文件。 全部,您要求的信息-甚至行号也包含在这些JSON文件中。
您可以将此功能请求用作参考-我们在其中添加了JSON文件以“自动化友好”的方式输出统计信息:https://github.com/intuit/karate/issues/561
由于到目前为止,您是唯一一个要求这样做的人,因此我们不太可能接受此请求-除非我们得到某种形式的社区贡献。希望有道理。