我如何选择不运行黄瓜功能

发布于 2024-11-08 21:44:01 字数 83 浏览 0 评论 0原文

如果我在 Windows 上,我想运行某些 Cucumber 功能。谷歌和黄瓜文档似乎在这里变得如此吸引人。

谢谢!

I want to not run certain cucumber feature if, say, I'm on windows. Google and the cucumber docs seemed to turn up dry so appealing here.

Thanks!

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

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

发布评论

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

评论(2

面如桃花 2024-11-15 21:44:01

支持泰勒的回答,我想提出以下附加信息:

使用 Cucumber Profiles

如果您正在运行系统在多个不同的环境中,您可能想要创建一个配置文件,然后简单地为您定义一个排除该文件的默认配置文件。

# config/cucumber.yml
##YAML Template
---
windows: --tags ~@not-windows
default: --tags @not-windows

执行(在非 Windows 系统上/默认)

$ cucumber

执行(在 Windows 系统上):

$ cucumber -p windows

您可以将默认值设置为当前所在的任何环境,这样您就不必记住哪些功能不执行;允许您只执行cucumber

使用 Cucumber Rake 任务

创建一个 rake 任务来检查您的环境并包含您想要的标签:

require 'rubygems'
require 'cucumber'
require 'cucumber/rake/task'

WINDOWS_PLATFORM = /mswin|win32|mingw/ unless defined? WINDOWS_PLATFORM

Cucumber::Rake::Task.new(:features) do |t|
  tags = (RUBY_PLATFORM =~ WINDOWS_PLATFORM ? "~@not-windows" : "@not-windows")
  t.cucumber_opts = "features #{tags}"
end

执行(在任一平台):

$ rake features

这应该根据您的环境自动包含正确的标签。

Supporting Tyler's answer I would like to propose this additional information:

Use Cucumber Profiles

If you are running the system on multiple different environments you may want to create a profile file and then simply define a default profile for you which excludes the file.

# config/cucumber.yml
##YAML Template
---
windows: --tags ~@not-windows
default: --tags @not-windows

Execution (on a non-windows system / default)

$ cucumber

Execution (on a windows system):

$ cucumber -p windows

You could set the default to whichever environment you are currently on to save yourself having to remember which features do not executing; allowing you to just execute cucumber.

Use Cucumber Rake Task

Create a rake task that checks your environment and includes the tag you want:

require 'rubygems'
require 'cucumber'
require 'cucumber/rake/task'

WINDOWS_PLATFORM = /mswin|win32|mingw/ unless defined? WINDOWS_PLATFORM

Cucumber::Rake::Task.new(:features) do |t|
  tags = (RUBY_PLATFORM =~ WINDOWS_PLATFORM ? "~@not-windows" : "@not-windows")
  t.cucumber_opts = "features #{tags}"
end

Execution (on either platform):

$ rake features

This should automatically include the right tag based on your environment.

绅士风度i 2024-11-15 21:44:01

解决这个问题的最佳方法可能是使用标签。

例如,如果您向某个功能添加像 @not-windows 这样的标签,那么您可以自定义您的 Cucumber 执行以忽略它。

@not-windows
Feature: Your feature that causes a problem
  your scenarios

如果您随后使用 cucumber --tags ~@not-windows 运行测试,它将运行所有未使用 @not-windows 标记的 cuke。 ~ 是导致“not”行为的原因,您可以通过执行 cucumber --tags @not-windows 来仅运行这些标签。在 Windows 中使用第一个 Cucumber 行,您可以阻止有问题的功能(或单个场景)运行,但如果您在另一个操作系统上并正常运行 Cucumber,这些功能仍然会运行。

参考:https://github.com/cucumber/cucumber/wiki/Tags

The best way to approach this would likely be using tags.

For example, if you add a tag like @not-windows to a feature you can then customize your cucumber execution to ignore this.

@not-windows
Feature: Your feature that causes a problem
  your scenarios

If you then run your tests with cucumber --tags ~@not-windows it will run all cukes that are not tagged by @not-windows. The ~ is what causes the "not" behavior, you could run ONLY these tags by doing cucumber --tags @not-windows. Using the first cucumber line while in Windows, you can block the problematic features (or individual scenarios) from running but if you're on another OS and run cucumber normally, these will still be ran.

Reference: https://github.com/cucumber/cucumber/wiki/Tags

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