cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
Highlighted
New Member

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

0

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Occasional Contributor

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

@tookythey're looking for an equivalent to JUnit 4s Error Collector.

https://junit.org/junit4/javadoc/4.12/org/junit/rules/ErrorCollector.html

This is not supported by by Cucumber but you can emulate it by storing all failed assertions somewhere and throwing them all in an after hook. This issue came up before in the past:

https://github.com/cucumber/cucumber-jvm/issues/771

View solution in original post

2 REPLIES 2
Highlighted
Staff

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

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?

Highlighted
Occasional Contributor

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

@tookythey're looking for an equivalent to JUnit 4s Error Collector.

https://junit.org/junit4/javadoc/4.12/org/junit/rules/ErrorCollector.html

This is not supported by by Cucumber but you can emulate it by storing all failed assertions somewhere and throwing them all in an after hook. This issue came up before in the past:

https://github.com/cucumber/cucumber-jvm/issues/771

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors