Tutorial 1: First Steps¶
Goal: | Show basics, make first steps |
---|
Write the Feature Test¶
The following feature file provides a simple feature with one scenario
in the known Given ... When ... Then ...
language style (BDD).
# file:features/tutorial01_basics.feature
Feature: Showing off behave (tutorial01)
Scenario: Run a simple test
Given we have behave installed
When we implement a test
Then behave will test it for us!
Provide the Test Automation¶
To be able to execute the feature file, you need to provide a thin
automation layer that represents the steps in the feature file
with Python functions. These step functions provide the test automation layer
(fixture code) that interacts with the system-under-test
(SUT).
# file:features/steps/step_tutorial01.py
# ----------------------------------------------------------------------------
# STEPS:
# ----------------------------------------------------------------------------
from behave import given, when, then
@given('we have behave installed')
def step_impl(context):
pass
@when('we implement a test')
def step_impl(context):
assert True is not False
@then('behave will test it for us!')
def step_impl(context):
assert context.failed is False
Run the Feature Test¶
When you run the feature file from above (with coloring enabled):
$ behave ../features/tutorial01_basics.feature Feature: Showing off behave (tutorial01) # ../features/tutorial01_basics.feature:1 Scenario: Run a simple test # ../features/tutorial01_basics.feature:3 Given we have behave installed # ../features/steps/step_tutorial01.py:12 When we implement a test # ../features/steps/step_tutorial01.py:16 Then behave will test it for us! # ../features/steps/step_tutorial01.py:20 1 feature passed, 0 failed, 0 skipped 1 scenario passed, 0 failed, 0 skipped 3 steps passed, 0 failed, 0 skipped, 0 undefined Took 0m0.001s
As alternative you can run the feature with plain formatting (or another formatter):
$ behave --format=plain --show-timings ../features/tutorial01_basics.feature Feature: Showing off behave (tutorial01) Scenario: Run a simple test Given we have behave installed ... passed in 0.000s When we implement a test ... passed in 0.000s Then behave will test it for us! ... passed in 0.000s 1 feature passed, 0 failed, 0 skipped 1 scenario passed, 0 failed, 0 skipped 3 steps passed, 0 failed, 0 skipped, 0 undefined Took 0m0.001s