bdd - Behave - Common features between applications, avoiding duplication -


i have many applications want test, have largely overlapping set of features. here oversimplified example of scenario might have:

given <name> playing game,  when shoot @ <color> target  should <event>  examples:   | name   | color | event |  | alice  | red   | hit   |  | alice  | blue  | miss  |  | bob    | red   | miss  |  | bob    | blue  | hit   |  | bob    | green | hit   | 

it's silly example, suppose have lot of players different hit/miss conditions, , want run just scenarios given name? say, want run tests alice. there's still advantage having hit/miss tests in single scenario outline (since, after all, they're closely related).

one approach duplicate test every name , tag them, like:

@alice given alice playing game  when shoots @ <color> target  should <event>  examples:  | color | event |  | red   | hit   |  | blue  | miss  | 

this way can run behave --tags @alice, i'm repeated same scenario every user, , that's lot of duplication. there way still compress examples 1 scenario - selectively run of them? what's right approach here?

version 1.2.5 introduced better ways distinguish scenario outlines. possible uniquely distinguish them , select unique scenario generated outline --name= @ command line. instance, suppose following feature file:

feature: test  scenario outline: test  given <name> playing game,  when shoot @ <color> target  should <event>   examples:   | name   | color | event |   | alice  | red   | hit   |   | alice  | blue  | miss  |   | bob    | red   | miss  |   | bob    | blue  | hit   |   | bob    | green | hit   | 

let's want run test bob, red, miss. in first table, 3rd row. so:

behave --name="@1.3" 

will select test. in version 1.2.5 , subsequent versions. generated scenario gets name includes "@<table number>.<row number>" <table number> number of table (starting 1) , <row number> number of row.

this won't allow select scenarios pertain single user. however, can achieve in way. can split examples in two:

 examples: alice   | name   | color | event |   | alice  | red   | hit   |   | alice  | blue  | miss  |   examples: bob   | name   | color | event |   | bob    | red   | miss  |   | bob    | blue  | hit   |   | bob    | green | hit   | 

the table names appear in generated scenario names , ask behave run tests associated 1 table:

behave --name="alice" 

i not know of way access example name in steps , rid of first column.

the full set of details in release notes 1.2.5.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -