与 Cucumber 的组合测试
我有一个包含两个不同变量的场景大纲。一个变量有大约 20 个不同的值,另一个有 3 个不同的值。
我需要能够测试每一个组合,并且我需要在单独的场景中测试每个组合,因为它们必须独立测试。
目前,我只是用手写出来(它们在示例中是整数,但在我的测试中不是):
Scenario Outline: Test my stuff
Given first var is <var_a>
And second var is <var_b>
When I do stuff
Then good stuff should happen
Examples:
| var_a | var_b |
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 1 |
| 2 | 2 |
etc...
问题:有没有一种方法可以运行这个,而不必写出每个组合?这些变量的大小和内容稍后必然会发生变化,我更希望有一个单一的数据结构来处理。
I have a scenario outline that has two different variables. One variable has about 20 different values and the other has 3.
I need to be able to test every single combination and I need each in a separate scenario since they must be tested independently.
Currently, I just write it out by hand(they are integers in the example but not in my test):
Scenario Outline: Test my stuff
Given first var is <var_a>
And second var is <var_b>
When I do stuff
Then good stuff should happen
Examples:
| var_a | var_b |
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 1 |
| 2 | 2 |
etc...
Question: Is there a way to run this where every combination doesn't have to be written out? The variables are bound to change in size and content later on and I would prefer to have a single data structure to deal with.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
@var_a_combos
和@var_b_combos
是一个包含每个的枚举
该类型的不同可能性。
当我运行每个组合时
将迭代两个变量并且
测试每一个组合。
它不使用断言,而是
将会创建一个
@results(String) 变量将
列出所有失败及其所需的信息
调试数据。
那么好事就会发生
将运行代码
@results.should
判断是否测试eql ""
案例通过/失败。
使用字符串变量来保存结果(而不是断言)的目的是确保在遇到第一次失败时测试不会停止。
我真的不喜欢这个解决方案,但这是迄今为止我能想到的最好的解决方案。我很欣赏其他答案,但这个测试确实是集成测试,我确实需要测试每个组合。
如果有人发布进一步的答案,我将对其进行审查,并在我认为更好的情况下更改已接受的答案。
@var_a_combos
and@var_b_combos
are an Enumerable that contains every
different possibility for that type.
When I run every combination
will iterate over both variables and
test every single combination.
Instead of using an assertion, it
will instead create a
@results(String) variable that will
list any failures and their required
debugging data.
Then good stuff should happen
will run the code
@results.should
to determine whether the testeql ""
case passed/failed.
The purpose of using a String variable to hold the results(instead of an assertion) is to ensure that testing does not stop when the first failure is encountered.
I really don't like this solution but it is the best I could come up with so far. I appreciate the other answers but this testing really is integration testing and I really do need to test every combination.
If anyone posts further answers I will review them and change the accepted answer if I think it is better.
由于测试是针对 UI 小部件的,并且您尝试在单元级别测试它,因此您应该查看 QUnit(或另一个 javascript 单元测试框架,但这是我个人的偏好)。您甚至可以通过 Cucumber 运行 QUnit 测试,如 使用 Cucumber 和 Capybara 测试排序
Since the tests are for a UI widget, and you're trying to test it at the unit level, you should check out QUnit (or another javascript unit testing framework, but this one's my personal preference). You can even run QUnit tests via cucumber, as in Test sorting with Cucumber and Capybara
您确定真的需要测试每个组合吗?你能解释一下这个问题的一些背景吗?
无论如何,关于在单独的场景中运行所有内容的查询,您需要一个带有示例的场景大纲。请参阅黄瓜文档。
Are you sure you really need to test every combination? Could you explain some context around the problem?
Anyway, regarding your query about running everything in a separate scenario, a Scenario Outline with examples is what you need. See the Cucumber docs.