Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to make cucumber test fail?

The piece of code I have below compares two list. In my step I use an if statement to check if the destinationList is empty, if so the test is correct and the cucumber steps should proceed.

However if the else statement is reached is there a way I can cause the cucumber test to fail? `

if (destinationList.isEmpty()) {
    System.out.println("This report is correct");

} else {
     System.out.println("This report is incorrect.");
     System.out.println("This list conatains the expected values of the report and their locations:");
     System.out.println("expected = "+sourceList);
     System.out.println("This list contains the actual value from this report and their locations:");
     System.out.println("actual = "+destinationList);
}
like image 215
Eoghan Buckley Avatar asked Oct 23 '25 03:10

Eoghan Buckley


2 Answers

Do you use JUnit as your test framework? If so then use

fail("Reason of fail")

This is a static method from class Assert http://junit.sourceforge.net/javadoc/org/junit/Assert.html

like image 179
arseniyandru Avatar answered Oct 27 '25 04:10

arseniyandru


I found the answer. I had first tried assert fail which wasn't working.

The correct syntax turned out to be Assert.fail(); which I included at the bottom of my else statement.

like image 38
Eoghan Buckley Avatar answered Oct 27 '25 02:10

Eoghan Buckley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!