4
在香草黃瓜,通過在步驟定義puts
呼叫輸出任何東西被捕獲作爲「測試輸出」,並相應地格式化,如下面的輸出例如:如何在Cucumber JVM中捕獲標準輸出(如Cucumber Ruby的輸入)?
Feature: A simple thing
Scenario: A simple scenario # features/simple.feature:3
Given I do a step # features/steps/step.rb:1
This text is output with puts
正如所看到的上面,這是有益地縮進以「漂亮」的輸出格式。 JSON格式,它甚至捕獲以結構化的方式:
"keyword": "Scenario",
"name": "A simple scenario",
"line": 3,
"description": "",
"id": "a-simple-thing;a-simple-scenario",
"type": "scenario",
"steps": [
{
"keyword": "Given ",
"name": "I do a step",
"line": 4,
"output": [
"This text is output with puts"
],
}
],
上面是通過一個普通特徵文件和一個步驟定義像以下產生:
Given(/^I do a step$/) do
puts 'This text is output with puts'
end
是否有等同功能時在Java中實現Cucumber步驟,我可以使用這個輸出捕獲相同的方式?打印到System.out
會導致繞過捕獲機制,就像在Ruby中使用STDOUT.puts
一樣。
與許多Ruby Cucumber的示例不同,我沒有看到任何使用此功能的Cucumber-JVM示例,但顯然在Cucumber-JVM的JSON輸出中輸入了「輸出」的條目,因此我想象一下,必須有一種方法來寫入該領域。