Cucumber 中的数据驱动测试

发布于 2024-08-03 01:01:25 字数 291 浏览 6 评论 0原文

我必须测试一个消息路由应用程序,其功能大致如下: - 消息发送到应用程序 - 应用程序检查消息 - 根据消息的内容将消息转发到某处

绝大多数测试用例几乎相同;生成特定类型的消息,将其加载到系统中,等待几秒钟,然后检查所需的目的地以确保消息被正确转发。

是否有一种推荐的方法来生成一个测试用例,并让它重复循环所有 (message, required_destination) 元组,而不是在 Cucumber 中生成数百个几乎相同的测试用例?为了便于维护,我更愿意将这些元组维护到 YAML 文件而不是数据库中,但这两种解决方案都可以。

I've got to test a message-routing application, whose functionality is broadly as follows:
- message gets sent to app
- app examines message
- message gets forwarded somewhere, based on the content of the message

The vast majority of test cases are near-identical; generate a particular type of message, load it into the system, wait a few seconds, then check the required destination to ensure that the message was forwarded correctly.

Rather than generate 100s of near-identical test cases in Cucumber, is there a recommended way to generate the one test case, and have it repeatedly cycle through all the (message, required_destination) tuples? I'd prefer to have these tuples maintained into a YAML file rather than a database, for ease of maintenance, but either solution would be fine.

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

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

发布评论

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

评论(2

黎歌 2024-08-10 01:01:25

您应该尝试使用示例场景大纲

正常场景

Scenario: Login
  Given I am on login page
  When I enter username "Jonas" and password "secrect" and press login
  Then I get redirected to "Jonas Home Page"

场景大纲

Scenario Outline: Login
  Given I am on login page
  When I enter username <username> and password <password> and press login
  Then I get redirected to <redirect_page>

Examples:
  | username | password | redirect_page     |
  | "Jonas"  | "secret" | "Jonas Home Page" |
  | "Anna"   | "Data"   | "Annas Home Page" |

阅读更多:
https://github.com/cucumber/cucumber/wiki/Scenario-Outlines

You should try Scenario Outline using Examples

Normal Scenario

Scenario: Login
  Given I am on login page
  When I enter username "Jonas" and password "secrect" and press login
  Then I get redirected to "Jonas Home Page"

Scenario Outline

Scenario Outline: Login
  Given I am on login page
  When I enter username <username> and password <password> and press login
  Then I get redirected to <redirect_page>

Examples:
  | username | password | redirect_page     |
  | "Jonas"  | "secret" | "Jonas Home Page" |
  | "Anna"   | "Data"   | "Annas Home Page" |

Read More:
https://github.com/cucumber/cucumber/wiki/Scenario-Outlines

¢蛋碎的人ぎ生 2024-08-10 01:01:25

我在黄瓜中没有这种情况,但我确实在规范中使用管道分隔文件进行海量数据测试,希望它会有所帮助:

您可以找到示例 此处为 DamerauLevenshteinMod 的说明在 read_test_file

我不明白为什么同样的方法也不能用于黄瓜。

I dont have this kind of situation in cucumber, but I do use pipe separated files in specs for massive data testing, hope it will help:

You can find examples here in description of DamerauLevenshteinMod and here in read_test_file

I dont see why the same approach cannot be used for cucumber as well.

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