如何将类似YML的数据结构传递给黄瓜场景?

发布于 2024-09-29 01:44:31 字数 126 浏览 0 评论 0原文

我想将类似YML的配置数据传递给黄瓜的场景。

例如:

category:
  subcategory:
    name: whay

如何做到这一点?谢谢

I want to pass YML-like config data to the scenario of cucumber.

for instance:

category:
  subcategory:
    name: whay

how to do this? thanks

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

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

发布评论

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

评论(1

生生漫 2024-10-06 01:44:31

遵循测试驱动的方法,考虑将 YML 解析逻辑与应用程序逻辑分开,例如:

def my_app_logic(my_hash)
  # app logic goes here
end

def my_yml_parsing_logic
  # load a file, or get a yml string
  # parse it and return a hash
end

然后,您将编写单元测试来检查 yml 解析逻辑及其所有边缘情况。您还可以为应用程序逻辑编写单元测试,而不必担心 yml。

对于您的黄瓜测试,请考虑模拟(或使用工厂来创建)一个好的哈希值进行测试,并在步骤定义中使用此哈希值,这样您就可以有一个类似以下的步骤:

When I run my app logic on a hash with 5 categories

或类似的简单内容。

Following a test-driven approach, consider separating the YML parsing logic from your application logic, with something like:

def my_app_logic(my_hash)
  # app logic goes here
end

def my_yml_parsing_logic
  # load a file, or get a yml string
  # parse it and return a hash
end

Then you would write unit tests to check the yml parsing logic and all its edge cases. You can also write unit tests for the app logic without having to worry about yml.

For your cucumber tests, consider mocking up (or using a factory to create) a good hash for testing, and use this hash in your step definition, so you can have a step like:

When I run my app logic on a hash with 5 categories

or something simple like that.

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