You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

randomize.feature 4.5 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. Feature: Randomize
  2. Use the `--order random` switch to run scenarios in random order.
  3. This is especially helpful for detecting situations where you have state
  4. leaking between scenarios, which can cause flickering or fragile tests.
  5. If you do find a random run that exposes dependencies between your tests,
  6. you can reproduce that run by using the seed that's printed at the end of
  7. the test run.
  8. For a given seed, the order of scenarios is constant, i.e. if step A runs
  9. before step B, it will always run before step B even if other steps are
  10. skipped.
  11. Background:
  12. Given a file named "features/bad_practice_part_1.feature" with:
  13. """
  14. Feature: Bad practice, part 1
  15. Scenario: Set state
  16. Given I set some state
  17. Scenario: Depend on state from a preceding scenario
  18. When I depend on the state
  19. """
  20. And a file named "features/bad_practice_part_2.feature" with:
  21. """
  22. Feature: Bad practice, part 2
  23. Scenario: Depend on state from a preceding feature
  24. When I depend on the state
  25. """
  26. And a file named "features/unrelated.feature" with:
  27. """
  28. Feature: Unrelated
  29. @skipme
  30. Scenario: Do something unrelated
  31. When I do something
  32. """
  33. And a file named "features/step_definitions/steps.rb" with:
  34. """
  35. Given(/^I set some state$/) do
  36. $global_state = "set"
  37. end
  38. Given(/^I depend on the state$/) do
  39. raise "I expect the state to be set!" unless $global_state == "set"
  40. end
  41. Given(/^I do something$/) do
  42. end
  43. """
  44. Scenario: Run scenarios in order
  45. When I run `cucumber`
  46. Then it should pass
  47. @global_state
  48. Scenario: Run scenarios randomized
  49. When I run `cucumber --order random:41544 -q`
  50. Then it should fail
  51. And the stdout should contain exactly:
  52. """
  53. Feature: Bad practice, part 1
  54. Scenario: Depend on state from a preceding scenario
  55. When I depend on the state
  56. I expect the state to be set! (RuntimeError)
  57. ./features/step_definitions/steps.rb:6:in `/^I depend on the state$/'
  58. features/bad_practice_part_1.feature:7:in `I depend on the state'
  59. Feature: Unrelated
  60. @skipme
  61. Scenario: Do something unrelated
  62. When I do something
  63. Feature: Bad practice, part 2
  64. Scenario: Depend on state from a preceding feature
  65. When I depend on the state
  66. I expect the state to be set! (RuntimeError)
  67. ./features/step_definitions/steps.rb:6:in `/^I depend on the state$/'
  68. features/bad_practice_part_2.feature:4:in `I depend on the state'
  69. Feature: Bad practice, part 1
  70. Scenario: Set state
  71. Given I set some state
  72. Failing Scenarios:
  73. cucumber features/bad_practice_part_1.feature:6
  74. cucumber features/bad_practice_part_2.feature:3
  75. 4 scenarios (2 failed, 2 passed)
  76. 4 steps (2 failed, 2 passed)
  77. Randomized with seed 41544
  78. """
  79. @force_legacy_loader
  80. Scenario: Rerun scenarios randomized
  81. When I run `cucumber --order random --format summary`
  82. And I rerun the previous command with the same seed
  83. Then the output of both commands should be the same
  84. @global_state
  85. Scenario: Run scenarios randomized with some skipped
  86. When I run `cucumber --tags "not @skipme" --order random:41544 -q`
  87. Then it should fail with exactly:
  88. """
  89. Feature: Bad practice, part 1
  90. Scenario: Depend on state from a preceding scenario
  91. When I depend on the state
  92. I expect the state to be set! (RuntimeError)
  93. ./features/step_definitions/steps.rb:6:in `/^I depend on the state$/'
  94. features/bad_practice_part_1.feature:7:in `I depend on the state'
  95. Feature: Bad practice, part 2
  96. Scenario: Depend on state from a preceding feature
  97. When I depend on the state
  98. I expect the state to be set! (RuntimeError)
  99. ./features/step_definitions/steps.rb:6:in `/^I depend on the state$/'
  100. features/bad_practice_part_2.feature:4:in `I depend on the state'
  101. Feature: Bad practice, part 1
  102. Scenario: Set state
  103. Given I set some state
  104. Failing Scenarios:
  105. cucumber features/bad_practice_part_1.feature:6
  106. cucumber features/bad_practice_part_2.feature:3
  107. 3 scenarios (2 failed, 1 passed)
  108. 3 steps (2 failed, 1 passed)
  109. Randomized with seed 41544
  110. """

No Description

Contributors (1)