Alan3212
Alan3212

Reputation: 1

running cucumber scenario 2000 times

There's a way to run one cucumber scenario 2000 times without using Scenario outline?

Scenario Outline:
  Run test n times
    |     1        |
    |     2       |

Upvotes: 0

Views: 53

Answers (1)

M.P. Korstanje
M.P. Korstanje

Reputation: 12039

Cucumber is a tool to support BDD. And BDD is a way for software teams to work that closes the gap between business people and technical people. This means that you should first think about how you communicate this to other people.

And you already did this in the title of this post. So write that down:

Scenario: Do it lots
  Given Jack wants to do a thing
  When Jack does the thing 2000 times
  Then that wasn't a problem.

So then

    private Supplier<Result> doTheThing;
    private List<Result> results = new ArrayList<>();
    
    @Given("Jack wants to do a thing")
    public void jack_wants_to_do_a_thing() {
        doTheThing = ()-> {
            // Do the thing, return a result;
            return result;
        };
    }

    @When("Jack does the thing {int} times")
    public void jack_does_the_thing(int repeat) {
        for (int i = 0; i < repeat; i++) {
            results.add(doTheThing.get());
        }
    }

    @Then("that was not a problem")
    public void that_was_not_a_problemd() {
        results.forEach(result -> {
            assertTrue(result.isOk(), result + " was not not ok");
        });
    }

Upvotes: 3

Related Questions