1

I have set up some tests in my project, that uses Mockito to mock some classes. To run those tests, I use Gradle. When running them locally, everything works and all tests pass. However, for one week now, one test is failing (in the GitLab CI/CD only) with the following exception:

java.lang.NoClassDefFoundError: Could not initialize class org.mockito.internal.creation.cglib.ClassImposterizer$3

Even when re-running a pipeline on an unmodified branch, the test fails now, while previously it did not.

gitlab-runner 15.0.0 is used for the CI/CD and docker image gradle:7-jdk17-focal. Mockito version is 1.10.19

szoszk
  • 349
  • 7
  • 22
  • The error message `Could not initialize class` means that there was a problem in a static initializer of the specified class. So in contrast to your question title the class is found but is unable to initialize itself correctly. This may very well have something to do with the environment the jvm is running in. Is there some other info you can provide? – SpaceTrucker Jul 27 '22 at 19:04
  • @SpaceTrucker What info could be potentially useful? The output of the CI/CD is very long, most of it debug info of other tests (that do not fail). I also checked if the official gradle image was updated, but the last update was 13 days ago and the last successful run of the check was 9 days ago, so I assume the same gradle image was used. The mocked class is supposed to be used as a Bean in an ApplicationContext of spring. The error is appearing when spring tries to create the bean. – szoszk Jul 27 '22 at 19:34
  • This may help further: https://stackoverflow.com/a/1416543/1466267 – SpaceTrucker Jul 27 '22 at 19:38
  • Thanks, I'm gonna check it out. However I'm still confused how this happened out of nowhere, as the exact same code used to work with the tests, and additionally it also works on my local machine. Also, the mocked class is very simple, just a few fields with one getter and one setter each and one constructor. No static methods or fields involved. – szoszk Jul 27 '22 at 19:52

0 Answers0