Is it possible to reuse a feature as the “Given” for another feature?

后端 未结 2 401
难免孤独
难免孤独 2021-01-04 19:10

Is it possible to reuse a feature as the \"Given\" for another feature?

Or am I trying to do something I shouldn\'t be trying to do

basically my features loo

相关标签:
2条回答
  • 2021-01-04 19:41

    The Problem

    What you're actually attempting is to reuse a scenario. This is no longer supported in Cucumber.

    Aside from other problems with this approach, your tests will be slower and interdependent, since you will be:

    1. driving account creation through a browser, and
    2. making all your tests dependent on the account-creation test passing.

    Don't do that.

    The Cucumber Way

    Generally, you should write your tests to work independently, although you can certainly reuse step definitions. So, in the general case, you might want to add shared steps like:

    1. Given that user account "Test User" does not exist
    2. Given that user account "Test User" exists

    which can then be included in your scenarios as needed. The nice thing about this approach is that the steps can create or delete users programmatically.

    Alternatively, if most of your tests will be on existing accounts, set up the default data set with the right user fixtures already in place. For the limited subset where you will be testing account creation, just add a scenario background that drives user deletion.

    0 讨论(0)
  • 2021-01-04 19:44

    In case you are using Javascript, I've created a package named reuse-cucumber-scenarios for calling a scenario by doing:

    Given the scenario "@scenario_tag"
    

    .

    Given the scenario "@scenario_tag" with parameters
    """
    {
      "1": ["step1_param1", "step1_param2"],
      "2": ["step2_param1", "step2_param2", "step2_param3"],
      "3": ["step3_param1", "step3_param2", "step3_param3"],
    }
    """
    

    or creating gherkin variables...

    Given the variable "$variable_name" is equal to
    """
    #JSON object
    """
    

    or creating scenario functions and calling them by doing...

    Given the scenario "@$scenario_function_tag" where variable "$variable_name" is "value_to_replace"
    

    and more...

    0 讨论(0)
提交回复
热议问题