Search code examples
maventestingcucumber

mvn test doesn't fail when Cucumber scenario fails


I have a RunCucumberTest class as described in the JUnit section here and a Cucumber scenario that fails when run from the gutter icon in IntelliJ.

However, why does mvn test build successfully?

[WARNING] Tests run: 482, Failures: 0, Errors: 0, Skipped: 12
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  02:10 min
[INFO] Finished at: 2021-01-04T15:54:51-05:00
[INFO] ------------------------------------------------------------------------

I can see in the log that the scenario failed:

............................................F--.....................................................................................
Failed scenarios:
com/rose/sample.feature:23 # Feature name
26 Scenarios (1 failed, 25 passed)
132 Steps (1 failed, 2 skipped, 129 passed)
0m0.596s
org.junit.ComparisonFailure: expected:<x> but was:<y>

Solution

  • After further Googling, I finally figured out the problem was due to having both JUnit and TestNG as dependencies in my project while using the JUnit Cucumber runner. Since I couldn't remove the JUnit and TestNG dependencies as they were inherited from a parent POM, I changed the Cucumber runner to use TestNG instead and it worked.


    I later found another, simpler solution: https://stackoverflow.com/a/19928639/4179032.