| 1 |
@sequential |
| 2 |
Feature: Steps Usage Formatter |
| 3 |
|
| 4 |
As a test writer |
| 5 |
I want to get an overview which step definitions are used and where |
| 6 |
To simplify the refactoring of step definitions (and features). |
| 7 |
|
| 8 |
. SOLUTION: Use StepsUsageFormatter in dry-run mode, like: |
| 9 |
. |
| 10 |
. behave --dry-run -f steps.usage features/ |
| 11 |
. |
| 12 |
. NOTE: This formatter corresponds to the "usage" formatter in cucumber. |
| 13 |
|
| 14 |
|
| 15 |
@setup |
| 16 |
Scenario: Feature Setup |
| 17 |
Given a new working directory |
| 18 |
And a file named "features/steps/passing_steps.py" with: |
| 19 |
""" |
| 20 |
from behave import step |
| 21 |
|
| 22 |
@step('{word:w} step passes') |
| 23 |
def step_passes(context, word): |
| 24 |
pass |
| 25 |
|
| 26 |
@step('{word:w} step fails') |
| 27 |
def step_passes(context, word): |
| 28 |
assert False, "XFAIL-STEP" |
| 29 |
""" |
| 30 |
And a file named "features/steps/unused_steps.py" with: |
| 31 |
""" |
| 32 |
from behave import step |
| 33 |
|
| 34 |
@step('an unused step') |
| 35 |
def step_unused(context): |
| 36 |
pass |
| 37 |
|
| 38 |
@step('another unused step') |
| 39 |
def step_another_unused(context): |
| 40 |
pass |
| 41 |
""" |
| 42 |
And a file named "features/steps/alice_steps.py" with: |
| 43 |
""" |
| 44 |
from behave import given, when, then |
| 45 |
|
| 46 |
@given('{person} lives in {city}') |
| 47 |
def step_given_person_lives_in_city(context, person, city): |
| 48 |
pass |
| 49 |
|
| 50 |
@when('I visit {person}') |
| 51 |
def step_when_visit_person(context, person): |
| 52 |
pass |
| 53 |
|
| 54 |
@then('I meet {person} in {city}') |
| 55 |
def step_then_meet_person_in_city(context, person, city): |
| 56 |
pass |
| 57 |
""" |
| 58 |
And a file named "features/steps/charly_steps.py" with: |
| 59 |
""" |
| 60 |
from behave import given, when, then |
| 61 |
|
| 62 |
@given('{person} works for {company}') |
| 63 |
def step_given_person_works_for_company(context, person, company): |
| 64 |
pass |
| 65 |
|
| 66 |
@when('I plan a meeting with {person}') |
| 67 |
def step_when_plan_meeting_with_person(context, person): |
| 68 |
pass |
| 69 |
|
| 70 |
@then('I meet him at the {company} office') |
| 71 |
def step_then_meet_him_at_company_office(context, company): |
| 72 |
pass |
| 73 |
""" |
| 74 |
And a file named "features/alice.feature" with: |
| 75 |
""" |
| 76 |
Feature: |
| 77 |
Scenario: Visit Alice |
| 78 |
Given Alice lives in Paris |
| 79 |
When I visit Alice |
| 80 |
Then I meet Alice in Paris |
| 81 |
|
| 82 |
Scenario: Visit Bob |
| 83 |
Given Bob lives in Berlin |
| 84 |
When I visit Bob |
| 85 |
Then I meet Bob in Berlin |
| 86 |
""" |
| 87 |
And a file named "features/bob.feature" with: |
| 88 |
""" |
| 89 |
Feature: |
| 90 |
Scenario: Visit Bob |
| 91 |
Given Bob lives in Barcelona |
| 92 |
When I visit Bob |
| 93 |
Then I meet Bob in Barcelona |
| 94 |
And a step passes |
| 95 |
""" |
| 96 |
And a file named "features/charly.feature" with: |
| 97 |
""" |
| 98 |
Feature: |
| 99 |
Scenario: Meeting with Charly |
| 100 |
Given Charly works for ACME |
| 101 |
When I plan a meeting with Charly |
| 102 |
Then I meet him at the ACME office |
| 103 |
""" |
| 104 |
|
| 105 |
|
| 106 |
@usecase.primary |
| 107 |
Scenario: Show step definitions usage with all features in dry-run mode |
| 108 |
When I run "behave --dry-run -f steps.usage features/" |
| 109 |
Then it should pass with: |
| 110 |
""" |
| 111 |
@given('{person} lives in {city}') # features/steps/alice_steps.py:3 |
| 112 |
Given Alice lives in Paris # features/alice.feature:3 |
| 113 |
Given Bob lives in Berlin # features/alice.feature:8 |
| 114 |
Given Bob lives in Barcelona # features/bob.feature:3 |
| 115 |
|
| 116 |
@when('I visit {person}') # features/steps/alice_steps.py:7 |
| 117 |
When I visit Alice # features/alice.feature:4 |
| 118 |
When I visit Bob # features/alice.feature:9 |
| 119 |
When I visit Bob # features/bob.feature:4 |
| 120 |
|
| 121 |
@then('I meet {person} in {city}') # features/steps/alice_steps.py:11 |
| 122 |
Then I meet Alice in Paris # features/alice.feature:5 |
| 123 |
Then I meet Bob in Berlin # features/alice.feature:10 |
| 124 |
Then I meet Bob in Barcelona # features/bob.feature:5 |
| 125 |
|
| 126 |
@given('{person} works for {company}') # features/steps/charly_steps.py:3 |
| 127 |
Given Charly works for ACME # features/charly.feature:3 |
| 128 |
|
| 129 |
@when('I plan a meeting with {person}') # features/steps/charly_steps.py:7 |
| 130 |
When I plan a meeting with Charly # features/charly.feature:4 |
| 131 |
|
| 132 |
@then('I meet him at the {company} office') # features/steps/charly_steps.py:11 |
| 133 |
Then I meet him at the ACME office # features/charly.feature:5 |
| 134 |
|
| 135 |
@step('{word:w} step passes') # features/steps/passing_steps.py:3 |
| 136 |
And a step passes # features/bob.feature:6 |
| 137 |
|
| 138 |
UNUSED STEP DEFINITIONS[3]: |
| 139 |
@step('{word:w} step fails') # features/steps/passing_steps.py:7 |
| 140 |
@step('an unused step') # features/steps/unused_steps.py:3 |
| 141 |
@step('another unused step') # features/steps/unused_steps.py:7 |
| 142 |
""" |
| 143 |
And note that "the UNUSED STEP DEFINITIONS are ordered by file location" |
| 144 |
But note that "step definitions from unused_steps.py are not used by any feature" |
| 145 |
|
| 146 |
|
| 147 |
@usecase.primary |
| 148 |
Scenario: Show step definitions usage with one feature (dry-run mode) |
| 149 |
When I run "behave --dry-run -f steps.usage features/alice.feature" |
| 150 |
Then it should pass with: |
| 151 |
""" |
| 152 |
@given('{person} lives in {city}') # features/steps/alice_steps.py:3 |
| 153 |
Given Alice lives in Paris # features/alice.feature:3 |
| 154 |
Given Bob lives in Berlin # features/alice.feature:8 |
| 155 |
|
| 156 |
@when('I visit {person}') # features/steps/alice_steps.py:7 |
| 157 |
When I visit Alice # features/alice.feature:4 |
| 158 |
When I visit Bob # features/alice.feature:9 |
| 159 |
|
| 160 |
@then('I meet {person} in {city}') # features/steps/alice_steps.py:11 |
| 161 |
Then I meet Alice in Paris # features/alice.feature:5 |
| 162 |
Then I meet Bob in Berlin # features/alice.feature:10 |
| 163 |
|
| 164 |
UNUSED STEP DEFINITIONS[7]: |
| 165 |
@given('{person} works for {company}') # features/steps/charly_steps.py:3 |
| 166 |
@when('I plan a meeting with {person}') # features/steps/charly_steps.py:7 |
| 167 |
@then('I meet him at the {company} office') # features/steps/charly_steps.py:11 |
| 168 |
@step('{word:w} step passes') # features/steps/passing_steps.py:3 |
| 169 |
@step('{word:w} step fails') # features/steps/passing_steps.py:7 |
| 170 |
@step('an unused step') # features/steps/unused_steps.py:3 |
| 171 |
@step('another unused step') # features/steps/unused_steps.py:7 |
| 172 |
""" |
| 173 |
But note that "step definitions from charly_steps.py, passing_steps.py are now no longer used" |
| 174 |
|
| 175 |
|
| 176 |
@usecase.primary |
| 177 |
Scenario: Show step definitions usage with two features (dry-run mode) |
| 178 |
When I run "behave --dry-run -f steps.usage features/alice.feature features/charly.feature" |
| 179 |
Then it should pass with: |
| 180 |
""" |
| 181 |
@given('{person} lives in {city}') # features/steps/alice_steps.py:3 |
| 182 |
Given Alice lives in Paris # features/alice.feature:3 |
| 183 |
Given Bob lives in Berlin # features/alice.feature:8 |
| 184 |
|
| 185 |
@when('I visit {person}') # features/steps/alice_steps.py:7 |
| 186 |
When I visit Alice # features/alice.feature:4 |
| 187 |
When I visit Bob # features/alice.feature:9 |
| 188 |
|
| 189 |
@then('I meet {person} in {city}') # features/steps/alice_steps.py:11 |
| 190 |
Then I meet Alice in Paris # features/alice.feature:5 |
| 191 |
Then I meet Bob in Berlin # features/alice.feature:10 |
| 192 |
|
| 193 |
@given('{person} works for {company}') # features/steps/charly_steps.py:3 |
| 194 |
Given Charly works for ACME # features/charly.feature:3 |
| 195 |
|
| 196 |
@when('I plan a meeting with {person}') # features/steps/charly_steps.py:7 |
| 197 |
When I plan a meeting with Charly # features/charly.feature:4 |
| 198 |
|
| 199 |
@then('I meet him at the {company} office') # features/steps/charly_steps.py:11 |
| 200 |
Then I meet him at the ACME office # features/charly.feature:5 |
| 201 |
|
| 202 |
UNUSED STEP DEFINITIONS[4]: |
| 203 |
@step('{word:w} step passes') # features/steps/passing_steps.py:3 |
| 204 |
@step('{word:w} step fails') # features/steps/passing_steps.py:7 |
| 205 |
@step('an unused step') # features/steps/unused_steps.py:3 |
| 206 |
@step('another unused step') # features/steps/unused_steps.py:7 |
| 207 |
""" |
| 208 |
But note that "step definitions from passing_steps.py, unused_steps.py are not used by any feature" |
| 209 |
|
| 210 |
|
| 211 |
@usecase.secondary |
| 212 |
Scenario: Show step definitions usage with all features in normal mode |
| 213 |
When I run "behave -f steps.usage features/" |
| 214 |
Then it should pass with: |
| 215 |
""" |
| 216 |
@given('{person} lives in {city}') # features/steps/alice_steps.py:3 |
| 217 |
Given Alice lives in Paris # features/alice.feature:3 |
| 218 |
Given Bob lives in Berlin # features/alice.feature:8 |
| 219 |
Given Bob lives in Barcelona # features/bob.feature:3 |
| 220 |
|
| 221 |
@when('I visit {person}') # features/steps/alice_steps.py:7 |
| 222 |
When I visit Alice # features/alice.feature:4 |
| 223 |
When I visit Bob # features/alice.feature:9 |
| 224 |
When I visit Bob # features/bob.feature:4 |
| 225 |
|
| 226 |
@then('I meet {person} in {city}') # features/steps/alice_steps.py:11 |
| 227 |
Then I meet Alice in Paris # features/alice.feature:5 |
| 228 |
Then I meet Bob in Berlin # features/alice.feature:10 |
| 229 |
Then I meet Bob in Barcelona # features/bob.feature:5 |
| 230 |
|
| 231 |
@given('{person} works for {company}') # features/steps/charly_steps.py:3 |
| 232 |
Given Charly works for ACME # features/charly.feature:3 |
| 233 |
|
| 234 |
@when('I plan a meeting with {person}') # features/steps/charly_steps.py:7 |
| 235 |
When I plan a meeting with Charly # features/charly.feature:4 |
| 236 |
|
| 237 |
@then('I meet him at the {company} office') # features/steps/charly_steps.py:11 |
| 238 |
Then I meet him at the ACME office # features/charly.feature:5 |
| 239 |
|
| 240 |
@step('{word:w} step passes') # features/steps/passing_steps.py:3 |
| 241 |
And a step passes # features/bob.feature:6 |
| 242 |
|
| 243 |
UNUSED STEP DEFINITIONS[3]: |
| 244 |
@step('{word:w} step fails') # features/steps/passing_steps.py:7 |
| 245 |
@step('an unused step') # features/steps/unused_steps.py:3 |
| 246 |
@step('another unused step') # features/steps/unused_steps.py:7 |
| 247 |
""" |
| 248 |
|
| 249 |
@corner.case |
| 250 |
Scenario: StepsUsageFormatter shows undefined steps |
| 251 |
Given a file named "features/undefined.feature" with: |
| 252 |
""" |
| 253 |
Feature: With undefined steps |
| 254 |
Scenario: |
| 255 |
Given a step is undefined |
| 256 |
Then another step is undefined |
| 257 |
""" |
| 258 |
When I run "behave --dry-run -f steps.usage features/alice.feature features/undefined.feature" |
| 259 |
Then it should fail with: |
| 260 |
""" |
| 261 |
0 features passed, 0 failed, 0 skipped, 2 untested |
| 262 |
0 scenarios passed, 0 failed, 0 skipped, 3 untested |
| 263 |
0 steps passed, 0 failed, 0 skipped, 2 undefined, 6 untested |
| 264 |
""" |
| 265 |
And the command output should contain: |
| 266 |
""" |
| 267 |
@given('{person} lives in {city}') # features/steps/alice_steps.py:3 |
| 268 |
Given Alice lives in Paris # features/alice.feature:3 |
| 269 |
Given Bob lives in Berlin # features/alice.feature:8 |
| 270 |
|
| 271 |
@when('I visit {person}') # features/steps/alice_steps.py:7 |
| 272 |
When I visit Alice # features/alice.feature:4 |
| 273 |
When I visit Bob # features/alice.feature:9 |
| 274 |
|
| 275 |
@then('I meet {person} in {city}') # features/steps/alice_steps.py:11 |
| 276 |
Then I meet Alice in Paris # features/alice.feature:5 |
| 277 |
Then I meet Bob in Berlin # features/alice.feature:10 |
| 278 |
|
| 279 |
UNUSED STEP DEFINITIONS[7]: |
| 280 |
@given('{person} works for {company}') # features/steps/charly_steps.py:3 |
| 281 |
@when('I plan a meeting with {person}') # features/steps/charly_steps.py:7 |
| 282 |
@then('I meet him at the {company} office') # features/steps/charly_steps.py:11 |
| 283 |
@step('{word:w} step passes') # features/steps/passing_steps.py:3 |
| 284 |
@step('{word:w} step fails') # features/steps/passing_steps.py:7 |
| 285 |
@step('an unused step') # features/steps/unused_steps.py:3 |
| 286 |
@step('another unused step') # features/steps/unused_steps.py:7 |
| 287 |
|
| 288 |
UNDEFINED STEPS[2]: |
| 289 |
Given a step is undefined # features/undefined.feature:3 |
| 290 |
Then another step is undefined # features/undefined.feature:4 |
| 291 |
""" |
| 292 |
|
| 293 |
|
| 294 |
@corner.case |
| 295 |
Scenario: StepsUsageFormatter shows all locations of undefined step usage |
| 296 |
|
| 297 |
Ensure that all location are shown where an undefined step is used |
| 298 |
|
| 299 |
Given a file named "features/undefined_duplicates.feature" with: |
| 300 |
""" |
| 301 |
Feature: With undefined steps |
| 302 |
|
| 303 |
Scenario: Same undefined step used twice |
| 304 |
Given a step is undefined |
| 305 |
And a step is undefined |
| 306 |
Then a step passes |
| 307 |
|
| 308 |
Scenario: Same undefined step used again |
| 309 |
Given a step passes |
| 310 |
And a step is undefined |
| 311 |
""" |
| 312 |
When I run "behave --dry-run -f steps.usage features/undefined_duplicates.feature" |
| 313 |
Then it should fail with: |
| 314 |
""" |
| 315 |
0 scenarios passed, 0 failed, 0 skipped, 2 untested |
| 316 |
0 steps passed, 0 failed, 0 skipped, 3 undefined, 2 untested |
| 317 |
""" |
| 318 |
And the command output should contain: |
| 319 |
""" |
| 320 |
UNDEFINED STEPS[3]: |
| 321 |
Given a step is undefined # features/undefined_duplicates.feature:4 |
| 322 |
And a step is undefined # features/undefined_duplicates.feature:5 |
| 323 |
And a step is undefined # features/undefined_duplicates.feature:10 |
| 324 |
""" |
| 325 |
|
| 326 |
@use_outline |
| 327 |
Scenario: Scenario Outlines should not cause duplicated step entries |
| 328 |
|
| 329 |
Scenario Outlines generate Scenarios that use the same step multiple times. |
| 330 |
This duplication should not be listed. |
| 331 |
|
| 332 |
Given a file named "features/use_scenario_outline.feature" with: |
| 333 |
""" |
| 334 |
Feature: |
| 335 |
Scenario Outline: |
| 336 |
Given a step <outcome1> |
| 337 |
When another step <outcome2> |
| 338 |
|
| 339 |
Examples: |
| 340 |
| outcome1 | outcome2 | |
| 341 |
| passes | passes | |
| 342 |
| passes | fails | |
| 343 |
""" |
| 344 |
When I run "behave --dry-run -f steps.usage features/use_scenario_outline.feature" |
| 345 |
Then it should pass with: |
| 346 |
""" |
| 347 |
0 scenarios passed, 0 failed, 0 skipped, 2 untested |
| 348 |
0 steps passed, 0 failed, 0 skipped, 0 undefined, 4 untested |
| 349 |
""" |
| 350 |
And the command output should contain: |
| 351 |
""" |
| 352 |
@step('{word:w} step passes') # features/steps/passing_steps.py:3 |
| 353 |
Given a step passes # features/use_scenario_outline.feature:3 |
| 354 |
When another step passes # features/use_scenario_outline.feature:4 |
| 355 |
|
| 356 |
@step('{word:w} step fails') # features/steps/passing_steps.py:7 |
| 357 |
When another step fails # features/use_scenario_outline.feature:4 |
| 358 |
""" |
| 359 |
But the command output should not contain: |
| 360 |
""" |
| 361 |
@step('{word:w} step passes') # features/steps/passing_steps.py:3 |
| 362 |
Given a step passes # features/use_scenario_outline.feature:3 |
| 363 |
When another step passes # features/use_scenario_outline.feature:4 |
| 364 |
Given a step passes # features/use_scenario_outline.feature:3 |
| 365 |
""" |
| 366 |
|
| 367 |
@use_outline |
| 368 |
Scenario: Scenario Outlines should not cause duplicated entries for undefined steps |
| 369 |
|
| 370 |
Scenario Outlines generate Scenarios that use the same step multiple times. |
| 371 |
This duplication should not be listed. |
| 372 |
|
| 373 |
Given a file named "features/scenario_outline_with_undefined.feature" with: |
| 374 |
""" |
| 375 |
Feature: |
| 376 |
Scenario Outline: |
| 377 |
Given a step is <status1> |
| 378 |
When another step is <status2> |
| 379 |
|
| 380 |
Examples: |
| 381 |
| status1 | status2 | |
| 382 |
| undefined | undefined | |
| 383 |
| undefined | undefined | |
| 384 |
""" |
| 385 |
When I run "behave --dry-run -f steps.usage features/scenario_outline_with_undefined.feature" |
| 386 |
Then it should fail with: |
| 387 |
""" |
| 388 |
0 scenarios passed, 0 failed, 0 skipped, 2 untested |
| 389 |
0 steps passed, 0 failed, 0 skipped, 4 undefined |
| 390 |
""" |
| 391 |
And the command output should contain: |
| 392 |
""" |
| 393 |
UNDEFINED STEPS[2]: |
| 394 |
Given a step is undefined # features/scenario_outline_with_undefined.feature:3 |
| 395 |
When another step is undefined # features/scenario_outline_with_undefined.feature:4 |
| 396 |
""" |
| 397 |
But the command output should not contain: |
| 398 |
""" |
| 399 |
UNDEFINED STEPS[2]: |
| 400 |
Given a step is undefined # features/scenario_outline_with_undefined.feature:3 |
| 401 |
Given a step is undefined # features/scenario_outline_with_undefined.feature:3 |
| 402 |
When another step is undefined # features/scenario_outline_with_undefined.feature:4 |
| 403 |
When another step is undefined # features/scenario_outline_with_undefined.feature:4 |
| 404 |
""" |