如何在黄瓜测试中的场景大纲示例中获取多行字符串?

发布于 2024-10-18 09:35:53 字数 298 浏览 2 评论 0原文

我想在场景大纲的示例部分中使用多行字符串。 怎么办呢?

例如,

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

它看起来不干净,也不起作用

I would like to use multiline strings in the Examples section of The Scenario Outline.
How to do that ?

eg

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

it does not look clean neither works

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

意犹 2024-10-25 09:35:53

我所做的是将文件中的长字符串分开(在我的例子中它是 json 的片段),当我需要字符串时,我只需加载所需的文件。

我在 Grails 中做到了,但应该非常相似:

读取文件的方法

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

Json 文件

"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
}

如果你在文件中设置了“””三引号,字符串结果也会有它。

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.

柏拉图鍀咏恒 2024-10-25 09:35:53

我优先考虑黄瓜输出,而不是小黄瓜输入,尽管一等奖是两者都很漂亮。因此,多行示例值对我来说没有意义,因为它们绝对会破坏黄瓜输出。

Cucumber 鼓励使用 文档字符串 进行多行数据的可读输出。它鼓励使用场景大纲对数据矩阵进行可读输出。我不认为它鼓励多行数据矩阵的可读输出。

如果您能提供一些很好的示例来说明在这种情况下输出的外观,它们可能会在 Cukes 论坛

或者,如果您想要做的只是迭代 Cucumber 功能中的多行数据,请为多行数据提供助记符名称,并在您的 Scenario 的 Examples 矩阵中提供这些助记符概述,并将助记符视为您在粘合代码中为实际数据读取的夹具文件的名称。

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.

如歌彻婉言 2024-10-25 09:35:53

您是否考虑过在字符串中使用 \n 来表示回车符?

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文