Debian Codegraph @

features/runner.use_stage_implementations.feature

raw
1 Feature: Use Alternate Step Implementations for Each Test Stage
2
3 As I tester and test writer
4 I want to run the same feature with other step implementations during different testing stages
5 So I can run quick checks in a development environment and detailed checks in a testlab.
6
7 . CONCEPT: TEST STAGE
8 . A test stage allows you to use different step/environment implementations
9 . compared to other test stage or the default, unnamed test stage.
10 .
11 . Examples for test stages are:
12 . * develop (using the development environment with more diagnostics)
13 . * product (using the product database, ...)
14 . * systemtest
15 . * systemint (system integration)
16 . * ...
17 .
18 . NOTE:
19 . Test stages can be used to adapt to different test environments
20 . while using these test stages.
21 .
22 .
23 . EXAMPLE DIRECTORY LAYOUT (with default stage and stage=testlab):
24 .
25 . features/
26 . +-- steps/ # -- Step implementations for default stage.
27 . | +-- foo_steps.py
28 . +-- testlab_steps/ # -- Step implementations for stage=testlab.
29 . | +-- foo_steps.py
30 . +-- *.feature
31 . +-- environment.py # -- Environment for default stage.
32 . +-- testlab_environment.py # -- Environment for stage=testlab.
33
34
35 @setup
36 Scenario: Feature Setup
37 Given a new working directory
38 And a file named "features/example1.feature" with:
39 """
40 Feature:
41 Scenario:
42 Given I do something in a test stage
43 """
44 And a file named "features/environment.py" with:
45 """
46 def before_all(context):
47 context.use_develop_environment = False
48 """
49 And a file named "features/steps/foo_steps.py" with:
50 """
51 from behave import step
52
53 @step('I do something in a test stage')
54 def step_do_something(context):
55 assert not context.config.stage
56 assert not context.use_develop_environment
57 """
58 And I remove the environment variable "BEHAVE_STAGE"
59
60 Scenario: Use stage=develop
61 Given a file named "features/develop_environment.py" with:
62 """
63 def before_all(context):
64 context.use_develop_environment = True
65 """
66 And a file named "features/develop_steps/foo_steps.py" with:
67 """
68 from behave import step
69
70 @step('I do something in a test stage')
71 def step_do_something(context):
72 assert context.config.stage == "develop"
73 assert context.use_develop_environment
74 """
75 When I run "behave -c --stage=develop features/example1.feature"
76 Then it should pass with:
77 """
78 1 feature passed, 0 failed, 0 skipped
79 1 scenario passed, 0 failed, 0 skipped
80 1 step passed, 0 failed, 0 skipped, 0 undefined
81 """
82 And the command output should contain:
83 """
84 Scenario: # features/example1.feature:2
85 Given I do something in a test stage # features/develop_steps/foo_steps.py:3
86 """
87
88 Scenario: Use default stage
89 Given I remove the environment variable "BEHAVE_STAGE"
90 When I run "behave -c features/example1.feature"
91 Then it should pass with:
92 """
93 1 feature passed, 0 failed, 0 skipped
94 1 scenario passed, 0 failed, 0 skipped
95 1 step passed, 0 failed, 0 skipped, 0 undefined
96 """
97 And the command output should contain:
98 """
99 Scenario: # features/example1.feature:2
100 Given I do something in a test stage # features/steps/foo_steps.py:3
101 """
102
103 Scenario: Use the BEHAVE_STAGE environment variable to define the test stage
104 Given I set the environment variable "BEHAVE_STAGE" to "develop"
105 When I run "behave -c features/example1.feature"
106 Then it should pass with:
107 """
108 1 feature passed, 0 failed, 0 skipped
109 1 scenario passed, 0 failed, 0 skipped
110 1 step passed, 0 failed, 0 skipped, 0 undefined
111 """
112 And the command output should contain:
113 """
114 Scenario: # features/example1.feature:2
115 Given I do something in a test stage # features/develop_steps/foo_steps.py:3
116 """
117 But note that "I should better remove it again (TEARDOWN PHASE)"
118 And I remove the environment variable "BEHAVE_STAGE"
119
120
121 Scenario: Using an unknown stage
122 When I run "behave -c --stage=unknown features/example1.feature"
123 Then it should fail with:
124 """
125 ConfigError: No unknown_steps directory
126 """