黄瓜:如何组织一个复杂的测试集 [英] Cucumber: how to organize a complex test set

查看:102
本文介绍了黄瓜:如何组织一个复杂的测试集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个版本的后端,我测试。我想对三个版本运行类似的功能规范。

I've got three versions of a backend that I'm testing. I would like to run similar feature specifications against the three versions.

最初,我想我只是组织一个目录结构中的一切,如:

Initially, I thought I'd just organize everything in a directory structure, as such:

features/
  v1/
    something.feature
    step_definitions/
      something_steps.rb
  v2/
    something.feature
    step_definitions/
      something_steps.rb
  v3/
    something.feature
    step_definitions/
      something_steps.rb

然而,黄瓜似乎拉平一切,这意味着,我结束了模棱两可的一步定义。

However, cucumber seems to flatten everything, which means that I end up with ambiguous step definitions.

然后我想到了以下结构:

I then thought of the following structure:

features/
  v1/
    something.feature
  v2/
    something.feature
  v3/
    something.feature
  step_definitions/
    something_steps.rb

我会在功能文件中定义一个变量,指示一个版本,在steps文件中有一堆ifs,根据版本变量选择代码路径。但是,我还没有找到一个明显的方法来定义该变量在功能文件中。

I'd define a variable in the feature file somewhere, indicating which version that one is for, and I'd have a bunch of "ifs" inside the steps file, to choose code paths depending on that version variable. However, I haven't found an obvious way of defining that variable in the feature file.

有没有办法我可以组织的东西,或者我只需要创建多种功能的根源,一是每个版本,这将是一个可怕的解决方案,因为这将意味着黄瓜多次调用?

Is there any way I can organize things, or will I just have to create multiple "feature" roots, one per version, which would be an awful solution given that it would mean multiple invocations of cucumber?

v1/
  features/
    something.feature
    step_definitions/
      something_steps.rb
v2/
  features/
    something.feature
    step_definitions/
      something_steps.rb
v3/
  features/
    something.feature
    step_definitions/
      something_steps.rb


推荐答案

为什么黄瓜的多次调用是坏事?个人而言,这就是我的做法,并运行所有三个功能从一个Rakefile,所以我不必一个接一个。

Why would multiple invocations of cucumber be a bad thing? Personally, that's how I'd do it, and run all three features from a Rakefile so I didn't have to do one after the other.

此外,如果冲突是如此之大,您要为每个版本重写整个步骤定义,也许您应该重新考虑如何措辞他们。如果你真的把它描述为做同样的事情,如果代码是如此不同?

Also, if the conflicts are so large that you're rewriting the entire step definition for each version, maybe you should reconsider how you're wording them. Should you really describe it as doing the same thing if the code is so different?

如果变化较小,那么我建议看看标签 hooks 来实现您想要的。

If the changes are smaller, then I'd suggest looking at tags and hooks to achieve what you want.

因此,您的功能可能如下所示:

So your feature might look like this:

@v1
Feature: some feature
  In order to test different versions
  As a cucumber user
  I want to be able to change step definitions based on what version feature is running

  Scenario: some scenario
    Given some thing
    When I pass some method
    Then I should get something

您的步骤定义可能如下所示:

And your step definition might look like this:

Before('@v1') do
  Thing = V1Thing
  VERSION = 1
end

Given /^some thing&/ do
  @thing = Thing.new
end

When /^I pass some method$/ do
  @thing.some_action!
end

Then /^I should get something$/
  thing = "something" if VERSION == 1
  thing = "something else" if VERSION == 2
  @thing.prop.should == thing
end

使用这种方法即使步骤定义是非常不同的,但我认为这将更难管理。

You can use this method even if the step definitions are very different, but I think it will be harder to manage.

这篇关于黄瓜:如何组织一个复杂的测试集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆