Forum Discussion

pranuta99's avatar
New Member
4 years ago

How to test multiple conditions in the 'Then' step of a CucumberBDD test?


We are using CucumberBDD for our tests. For assertions we use JUnit. Now in our Given, When, Then steps we use multiple 'And' steps which do variety of activities. Until this point this is fine, we were able to do it. At the last 'Then' step should be final check whether the Scenario has PASSED or FAILED, based on the multiple 'And' steps of 'Then' branch itself.

One solution is to use JUnitSoftAssertions from assertJ library to pool multiple checks, if it is a pure JUnit project which our project is NOT.

As per Cucumber documentation, it only supports JUnit Assert class and it's various assertion methods, nothing more. According to that, you can have only one assertion per scenario.

Is there any means you can incorporate multiple checks which may fail or pass individually, after the final 'Then' step by using keyword 'And' multiple times?

2 Replies

  • tooky's avatar
    SmartBear Alumni (Retired)

    Cucumber has been designed to fail on first failure - so if a `Then` step fails it will not continue and run the next steps.


    I think what you are describing is trying to check multiple related things at the same time? You want to see if any or all of the outcomes pass or fail in one place?

    It might be easier to talk about a concrete example. Would it be possible for you to post a simple example of the Gherkin?