Is it possible to make cucumber test fail?

12,538

Solution 1

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

Solution 2

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.

Share:
12,538
Eoghan Buckley
Author by

Eoghan Buckley

Updated on June 04, 2022

Comments

  • Eoghan Buckley
    Eoghan Buckley almost 2 years

    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);
    }
    
  • AndyN
    AndyN almost 8 years
    Or, rather than putting fail in an if statement, you could simply use Assert.assertTrue(destinationList.isEmpty());