0

I'm upgrading my code from Java v1.8 to v11.0.8. All went fine until I run the tests mvn test and Mockito starts having issues. Every test errors-out. My versions of Mockito are fine (2.23.4) according to other answers here so I go to run just 1 test to narrow down the problem - it runs fine. So I run all the tests by right-clicking in Eclipse on my src/test/java and choosing Run As > JUnit test. Again, all run fine.

Note: I hesitate to add the error message here because the code works (as noted above), so this can be a distraction, but this question got a close request for lack of error message!

You are seeing this disclaimer because Mockito is configured to create inlined mocks.
You can learn more about inline mocks and their limitations under #39 of the Mockito class javadoc
Underlying exception: org.mockito.exceptions.base.MockitoException: Could not modify all classes [..., ..., ...]
at ...
at ...
Caused by org.springframework.beans.BeanInstantiationException: Failed to instantiate [..]: Factory method '...' threw exception; nested exception is org.springframework.beans.BeanCreationException: Error creating bean with name '...' defined in...
Mockito cannot mock this class: ...

If you're not sure why you're getting this error, please report to the mailing list.

The app itself runs fine with springboot:run clean

My tests always ran with only test as the goal, that is confirmed for me here, so what's changed?

I also see references to: Bytebuddy in that article but I have a good version of that too (1.9.16)

4
  • 1
    What version of Maven are you using? More specific: which version of the compiler plugin? maven.apache.org/guides/getting-started/…
    – Fullslack
    Commented Sep 21, 2020 at 13:01
  • Thanks @Fullslack.dev for pointing that out. I had no compiler plugin in my pom.xml so presume it was using default. I'm using Maven 3.6.3 so I added the latest compiler plugin (and maven.compiler.release) but no change to what I'm seeing on running the tests :( Commented Sep 21, 2020 at 14:27
  • 1
    If you are using spring-boot don't define dependencies like bytebuddy yourself not use the ones which are defiend by spring boot...furthermore check your version of mockito cause it's too old...use 3.X mockito version...and also your are using inline mockito which means your want to mock final classes ...
    – khmarbaise
    Commented Sep 21, 2020 at 16:18
  • Upgraded Mockito and tweeked versions of Junit Jupiter and it started working. Learnt a lot about pom tools in Eclipse that I'd kinda ignored before! @khmarbaise please make your comment into a reply so I can mark it correct. Commented Sep 22, 2020 at 17:10

0

Browse other questions tagged or ask your own question.