方案大纲:使用白名单&范围?
我一直在建立一个黄瓜自动化框架,并有许多要测试的组件。我已经使用了方案大纲来捕获各种值及其预期响应。
我认为的问题: 我必须指定每种类型的数据输入和错误消息。从下面的示例场景概述中,您可以看到我有一定的数字,所有这些都希望返回一条消息。如果有什么不等于这些值,返回错误消息:
Scenario Outline: Number is or is not valid
Given I send an event with the "Number" set to <num>
Then I will receive the following <message>
Examples:
| num | message |
| 0 | "Processed event" |
| 1 | "Processed event" |
| 2 | "Processed event" |
| 3 | "Processed event" |
| 4 | "Processed event" |
| 5 | "Processed event" |
| 6 | "Message failed" |
| -1 | "Message failed" |
| "One" | "Message failed" |
我想做什么: 我基本上希望在方案概述中定义了一个良好数据的“白名单”,如果有其他值输入 - 它返回了预期的错误消息。像以下内容:
Scenario Outline: Number is or is not valid
Given I send an event with the "Number" set to <num>
Then I will receive the following <message>
Examples:
| num | message |
| 0-5 | "Processed event" |
| Anything else | "Message failed" |
背后的代码是否可以使用?如您所见,它将具有使自动化套件更加简洁和可维护的好处。如果是这样,请告诉我,渴望讨论。
谢谢!
柯斯蒂
I have been building up a Cucumber automation framework and have a number of components to test. I have used Scenario Outline's to capture various values and their expected responses.
What I see as a problem:
I have to specify every single type of input of data and the error message to go with it. From the example Scenario Outline below you can see I have certain numbers that all are expected to return the one message. If anything does not equal these values the return an error message:
Scenario Outline: Number is or is not valid
Given I send an event with the "Number" set to <num>
Then I will receive the following <message>
Examples:
| num | message |
| 0 | "Processed event" |
| 1 | "Processed event" |
| 2 | "Processed event" |
| 3 | "Processed event" |
| 4 | "Processed event" |
| 5 | "Processed event" |
| 6 | "Message failed" |
| -1 | "Message failed" |
| "One" | "Message failed" |
What I would like to do:
I would basically like to have a "whitelist" of good data defined in the Scenario Outline and if there is any other value input - it returns the the expected error message. Like the following:
Scenario Outline: Number is or is not valid
Given I send an event with the "Number" set to <num>
Then I will receive the following <message>
Examples:
| num | message |
| 0-5 | "Processed event" |
| Anything else | "Message failed" |
Is the following possible with the code behind it? As you can see it would have benefits of making an automation suite far more concise and maintainable. If so please let me know, keen to discuss.
Thanks!
Kirsty
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
cucumber是支持bdd 的工具。这意味着当您必须交流行为时,它的工作原理非常好。但是,这个特殊的问题正在验证事件验证器的属性,即基于属性的测试。因此,相应地分配测试策略可能值得。
看来有一个规则,即处理有效的事件结果并拒绝无效的事件。这是您可以用黄瓜测试的东西。例如:
看来有一个规则,即有效事件在0-5之间设置了一个字段“编号”。而且由于听起来像是JSON对象,所以我猜想字符串“ 0”,“ 1”,“ 2”,“ 3”,“ 4”,“ 5”也有效。其他任何事情都是无效的。
详尽测试的一种好方法是使用基于属性的测试框架。例如 jqwik 。给定一组有效或无效值的描述,它将随机尝试一些。对于简化的示例:
以这种方式拆分黄瓜测试,描述了系统应如何响应有效和无效的事件。虽然JQWIK测试描述了有效事件的属性是什么。这使得第二次更加清晰,并且在第二个方面具有更大的保真度。
Cucumber is a tool to support BDD. This means that it works really well when you have to communicate about behavior. But this particular problem is going towards validating the properties of the event validator, i.e. property based testing. So it might be worth to split the test strategy accordingly.
It appears there is a rule that valid events results are processed and invalid events are rejected. This is something you could test with Cucumber. For example:
It also appears there is a rule that valid events have a field "Number" set to any value between 0-5. And since sounds like a json object I'm guessing the strings "0", "1", "2", "3", "4", "5" are also valid. Anything else is invalid.
A good way to test this exhaustively is by using property based testing framework. For example JQwik. Given a description of a set of either valid or invalid values it will randomly try a few. For a simplified example:
Split this way the Cucumber tests describe how the system should respond to valid and invalid events. While the JQwik test describe what the properties of a valid and invalid event are. This allows much more clarity on the first and a greater fidelity on the second.