Search code examples
javajunitcucumberserenity-bddcucumber-serenity

@RunWith(CucumberWithSerenity.class) throws NoClassDefFound cucumber/runtime/junit/Assertions


Trying to run Cucumber with Serenity using JUnit 5.

When the Test Runner has a @RunWith(Cucumber.class) annotation, the tests run, although Serenity does not record the outcome.

When the Test Runner has @RunWith(CucumberWithSerenity.class), a "NoClassDefFound cucumber/runtime/junit/Assertions" is thrown.

I thought it may be JUnit 5, so I switched to JUnit 4 and the same outcome happens.

I loaded the sample project into GitHub: https://github.com/WB3Tech/Cucumber-Serenity-JUnit5

The goal is to build the project then be able to see the Cucumber results in the Serenity html output.

Anyone have an idea of where I may be going wrong?


Solution

  • There were two separate issues:

    Dependency | cucumber-java - > v4.2.0

    I was using v4.7.1. When I rolled back to 4.2.0 from 4.7.1, the NoClassDefFound error went away. When I bumped up to 4.2.1, I got a new NoClassDefFound error. I tried all the versions from 4.2.1 to 4.7.1 and got different NoClassDefFound errors.

    Dependency | serenity-cucumber4 - v1.0.17

    When I used v1.0.17, a warning about missing dependencies comes up. When I used v1.0.15, this missing dependencies warning disappears.

    There looks to be bad references to a v2.0.59 of serenity-screenplay and serenity-screenplay-webdriver used by serenity-cucumber4 that do not exist in the maven repo.

    This was another obstacle I ran into that was not discussed in the primary issue

    Solutions

    • I kept cucumber-java at v4.2.0
    • I kept serenity-cucumber4 at v1.0.15

    All is working now

    You can read more about how I approached solving the problem at: https://github.com/serenity-bdd/serenity-cucumber4/issues/9

    You can also see the repo here: https://github.com/WB3Tech/Cucumber-Serenity-JUnit5

    I upgrade to Java 12, and half-way implemented JUnit5. The TestRunner is not using the @ExtendWith() attribute that replaced @RunWith, it is still using the @RunWith() attribute from the jupiter-vintage package.