如何在黄瓜测试中的场景大纲示例中获取多行字符串?
我想在场景大纲的示例部分中使用多行字符串。 怎么办呢?
例如,
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我所做的是将文件中的长字符串分开(在我的例子中它是 json 的片段),当我需要字符串时,我只需加载所需的文件。
我在 Grails 中做到了,但应该非常相似:
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:
我优先考虑黄瓜输出,而不是小黄瓜输入,尽管一等奖是两者都很漂亮。因此,多行示例值对我来说没有意义,因为它们绝对会破坏黄瓜输出。
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 yourScenario Outline
, and treat the mnemonics as the names of fixture files that you read for the actual data in your glue code.您是否考虑过在字符串中使用 \n 来表示回车符?
Have you considered using \n in your strings to denote the carriage return?