Skip to main content

BDD Cucumber exceptions

 

Arity Mismatch

An arity mismatch exception cucumber.runtime.CucumberException: Arity mismatch indicates that the step does not provide the right number of arguments needed for the step definition.

How do I fix a Cucumber-JVM error where the stacktrace contains ‘Failed to instantiate public cucumber.runtime.java.JavaBackend’ or ‘NoSuchMethodException’?

Check that the Cucumber version is the same for all Cucumber dependencies and make sure you only have the required dependencies. This means you need to ensure that you get the transitive dependencies that go with the version of Cucumber that you have.

You can see all your Maven dependencies, including transitive ones by running mvn dependency:tree.

If you’re using any other library which also contains a dependency on Cucumber (a transitive dependency), try excluding that transitive dependency in your pom file to ensure only one version of Cucumber is being referenced. Please refer to the Maven instructions for excluding dependencies for steps on excluding transitive dependencies.

Exception in thread "main" cucumber.runtime.CucumberException: No backends were found. Please make sure you have a backend module on your CLASSPATH.

Solution

Most probably this means that your cucumber-java version and java version on your machine is not compatible with each other.  First, check Java Version on your machine by going through this article How to check Java/JDK Version Installed on your Machine.

On my machine, I have Java 1.8.0 with cucumber-Java8-1.2.5 and it did not work. When I degraded my cucumber java version to cucumber-Java-1.2.5, it worked fine for me. Just make sure that first, you remove the cucumber-java which did not work for you from Project build path >> Libraries and then add new. Keeping both may create further issues for you.

Exception in thread "main" java.lang.NoClassDefFoundError: gherkin/formatter/Formatter

Solution

*This means that the Gherkin version you are using is not compatible with other Cucumber libraries. I tried using the latest gherkin3-3.0.0  but it did not work for me, so I degraded it to gherkin-2.12.2