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);
}
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With