Python のビヘイビアライブラリでは、次のようにパラメーター化されたシナリオ アウトラインを使用して機能ファイルを作成できます (このチュートリアルから適応)。
# feature file
Feature: Scenario Outline Example
Scenario Outline: Use Blender with <thing>
Given I put "<thing>" in a blender
When I switch the blender on
Then it should transform into "<other thing>"
Examples: Amphibians
| thing | other thing |
| Red Tree Frog | mush |
| apples | apple juice |
対応するステップ定義は次のようになります。
# steps file
from behave import given, when, then
from hamcrest import assert_that, equal_to
from blender import Blender
@given('I put "{thing}" in a blender')
def step_given_put_thing_into_blender(context, thing):
context.blender = Blender()
context.blender.add(thing)
@when('I switch the blender on')
def step_when_switch_blender_on(context):
context.blender.switch_on()
@then('it should transform into "{other_thing}"')
def step_then_should_transform_into(context, other_thing):
assert_that(context.blender.result, equal_to(other_thing))
ご覧のとおり、機能ファイルからステップ関数にパラメーターを渡す方法は次のとおりです。
- 山かっこで囲まれた機能ファイルでそれらを明示的に言及することにより
- 次に、ステップ関数のデコレーターに、中括弧で囲まれた同じ単語を含めます (山括弧を再度使用しないのはなぜですか?!)。
- 最後に、これらの単語をステップ関数の関数引数として挿入します。
ただし、多くの列を持つ大きなテーブルの例を考えると、これはすぐに読み書きが面倒になります。
# feature file
Feature: Large Table Example
Scenario Outline: Use Blender with a lot of things
Given I put "<first_thing>", "<second_thing>", "<third_thing>", "<fourth_thing>", "<fifth_thing>", "<sixth_thing>", "<seventh_thing>" in a blender
When I switch the blender on
Then it should transform into "<other thing>"
Examples: Things
| first thing | second thing | third thing | fourth thing | fifth thing | sixth thing | seventh thing |
| a | b | c | d | e | f | g | h |
| i | j | k | l | m | n | o | p |
# steps file
@given('I put "{first_thing}", "{second_thing}", "{third_thing}", "{fourth_thing}", "{fifth_thing}", "{sixth_thing}", "{seventh_thing}", in a blender')
def step_given_put_thing_into_blender(context, first_thing, second_thing, third_thing, fourth_thing, fifth_thing, sixth_thing, seventh_thing):
context.blender = Blender()
context.blender.add(thing)
...
その点は明らかだと思います。それらすべてを明示的に言及することなく、大きなテーブルからステップ定義に例を転送する可能性はありますか? たとえば、それらはテキストで言及されていなくてもコンテキスト変数のどこかに保存されていますか (まだそこには見つかりませんでした)?