Cucumber:如何组织复杂的测试集
我正在测试三个版本的后端。我想针对这三个版本运行类似的功能规范。
最初,我以为我只是将所有内容组织在目录结构中,如下所示:
features/
v1/
something.feature
step_definitions/
something_steps.rb
v2/
something.feature
step_definitions/
something_steps.rb
v3/
something.feature
step_definitions/
something_steps.rb
但是,黄瓜似乎将所有内容展平,这意味着我最终会得到不明确的步骤定义。
然后我想到了以下结构:
features/
v1/
something.feature
v2/
something.feature
v3/
something.feature
step_definitions/
something_steps.rb
我会在功能文件中的某处定义一个变量,指示该变量适用于哪个版本,并且在步骤文件内有一堆“if”,以根据情况选择代码路径该版本变量。但是,我还没有找到在功能文件中定义该变量的明显方法。
有什么方法可以组织事物,或者我只需要创建多个“功能”根,每个版本一个,这将是一个糟糕的解决方案,因为这意味着多次调用黄瓜?
v1/
features/
something.feature
step_definitions/
something_steps.rb
v2/
features/
something.feature
step_definitions/
something_steps.rb
v3/
features/
something.feature
step_definitions/
something_steps.rb
I've got three versions of a backend that I'm testing. I would like to run similar feature specifications against the three versions.
Initially, I thought I'd just organize everything in a directory structure, as such:
features/
v1/
something.feature
step_definitions/
something_steps.rb
v2/
something.feature
step_definitions/
something_steps.rb
v3/
something.feature
step_definitions/
something_steps.rb
However, cucumber seems to flatten everything, which means that I end up with ambiguous step definitions.
I then thought of the following structure:
features/
v1/
something.feature
v2/
something.feature
v3/
something.feature
step_definitions/
something_steps.rb
I'd define a variable in the feature file somewhere, indicating which version that one is for, and I'd have a bunch of "ifs" inside the steps file, to choose code paths depending on that version variable. However, I haven't found an obvious way of defining that variable in the feature file.
Is there any way I can organize things, or will I just have to create multiple "feature" roots, one per version, which would be an awful solution given that it would mean multiple invocations of cucumber?
v1/
features/
something.feature
step_definitions/
something_steps.rb
v2/
features/
something.feature
step_definitions/
something_steps.rb
v3/
features/
something.feature
step_definitions/
something_steps.rb
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么多次调用 Cucumber 会是一件坏事?就我个人而言,我就是这样做的,并从 Rakefile 运行所有三个功能,这样我就不必一个接一个地执行。
另外,如果冲突太大以至于您要重写每个版本的整个步骤定义,也许您应该重新考虑如何措辞它们。如果代码如此不同,您真的应该将其描述为做同样的事情吗?
如果更改较小,那么我建议查看 标签 和 hooks 来实现你想要的。
因此,您的功能可能如下所示:
您的步骤定义可能如下所示:
即使步骤定义非常不同,您也可以使用此方法,但我认为这将更难管理。
Why would multiple invocations of cucumber be a bad thing? Personally, that's how I'd do it, and run all three features from a Rakefile so I didn't have to do one after the other.
Also, if the conflicts are so large that you're rewriting the entire step definition for each version, maybe you should reconsider how you're wording them. Should you really describe it as doing the same thing if the code is so different?
If the changes are smaller, then I'd suggest looking at tags and hooks to achieve what you want.
So your feature might look like this:
And your step definition might look like this:
You can use this method even if the step definitions are very different, but I think it will be harder to manage.