我想在方案轮廓的示例部分中使用多线字符串。 怎么做?

,例如

Scenario Outline:
  Given something
  When `<action>` happens
    I should get elaborative `<duuh>`
  Examples:
    |action|duuh|
    |"""
    tututuut
    """|"""blablabla m
    ultiline"""|
.

它看起来不起作用

有帮助吗?

解决方案

I prioritize the cucumber output, not the Gherkin input, although first prize is for both to be beautiful. So multiline example values don't make sense for me, because they absolutely wreck the cucumber output.

Cucumber encourages readable output for multiline data with doc strings. It encourages readable output for data matrices with scenario outlines. I don't think it encourages readable output of multiline data matrices.

If you could come up with great examples of how the output would look in such cases, they might be well received on the Cukes forum.

Alternatively, if all you're trying to do is iterate over multiline data in your Cucumber features, come up with mnemonic names for the multiline data, provide those mnemonics in the Examples matrix of your Scenario Outline, and treat the mnemonics as the names of fixture files that you read for the actual data in your glue code.

其他提示

What I did, was to separate the long strings in files (in my case it was pieces of json) and when I need the strings, I just load the needed file.

I did it in Grails, but should be very similar:

Method to read the file

static String getMockJsonFile(String fileName){
    new File("${BOOKING_JSON_FILES_PATH}${fileName}.json").text
}

Json file

"collectionSummary": {
"attempts": [
{
"collectionMethod": {
"creditCardCollectionMethod": {
"id": 2,
"collectionMethodType": "CREDITCARD",
"creditCardType": {
"code": "CA",
"name": "Master Card Credit"
}
}
},
"billingCurrency": "EUR"
}
],
"creationDate": "2017-05-30 14:46:19",
"currency": "EUR",
"collectedAmount": 9.1
}

If you set """ triple quotes in the file, the string result will have it too.

Have you considered using \n in your strings to denote the carriage return?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top