Skip to content
Advertisement

Cucumber With JUnit java.lang.ExceptionInInitializerError

I’m new to the UnitTesting and Cucumber, and today I tried to implement a simple example from a tutorial in Intelij and Eclipse and I got the same error when I try run the TestRunner.java.

My pom.xml:

JavaScript

File .feature

JavaScript

TestRunner.java

JavaScript

Steps

JavaScript

My file structure:

enter image description here

And the error:

1 Scenarios (1 failed) 4 Steps (1 failed, 3 skipped) 0m0,225s

java.lang.ExceptionInInitializerError … Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.util.Comparator java.util.TreeMap.comparator accessible: module java.base does not “opens java.util” to unnamed module @378bf509

Advertisement

Answer

The Cucumber version you’re using is very outdated.

It still contained the XStream library which had this buggy behaviour.

XStream has been removed from Cucumber since version 3

Cucumber 1.x and 2.x used a library called XStream as a central building block for both data tables and type conversion.

However the usage of XStream in combination with Cucumber was poorly documented and it did not allow for the use of other Object Mappers (e.g. Jackson) which made it impossible to reuse domain objects. As XStream is not compatible with Java 9 it was also problem in long term.

Updated your dependencies to

JavaScript

Then you’ll have to update your different imports to include those instead because the packages have changed

JavaScript

When this is all done, I get the expected printed out when performing a mvn test

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement