You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running tests individually or in Eclipse, they all succeed. When run all together in Maven, Mockito throws this exception: Mockito cannot mock this class: class ___. Mockito can only mock non-private & non-final classes even if the class is non-private (protected), non-final and non-static.
How to reproduce it
1.- Delete this from the pom.xml file
<forkMode>always</forkMode>
2.- Run mvn package in the command line
Stacktrace
[ERROR] com.hotels.mutantswarm.report.ReportTest.testingReport Time elapsed: 0.014 s <<< ERROR!
org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: class com.hotels.mutantswarm.report.Line.
Mockito can only mock non-private & non-final classes.
If you're not sure why you're getting this error, please report to the mailing list.
Java : 1.8
JVM vendor name : AdoptOpenJDK
JVM vendor version : 25.265-b01
JVM name : OpenJDK 64-Bit Server VM
JVM version : 1.8.0_265-b01
JVM info : mixed mode
OS name : Mac OS X
OS version : 10.15.7
Underlying exception : org.mockito.exceptions.base.MockitoException:
Cannot create mock for class com.hotels.mutantswarm.report.Line
The type is not public and its mock class is loaded by a different class loader.
This can have multiple reasons:
- You are mocking a class with additional interfaces of another class loader
- Mockito is loaded by a different class loader than the mocked type (e.g. with OSGi)
- The thread's context class loader is different than the mock's class loader
Caused by: org.mockito.exceptions.base.MockitoException:
Cannot create mock for class com.hotels.mutantswarm.report.Line
The type is not public and its mock class is loaded by a different class loader.
This can have multiple reasons:
- You are mocking a class with additional interfaces of another class loader
- Mockito is loaded by a different class loader than the mocked type (e.g. with OSGi)
- The thread's context class loader is different than the mock's class loader
The text was updated successfully, but these errors were encountered:
massdosage
changed the title
Mockito bug
Mockito "cannot mock this class" error when running multiple tests in single JVM
Feb 1, 2021
The problem
When running tests individually or in Eclipse, they all succeed. When run all together in Maven, Mockito throws this exception:
Mockito cannot mock this class: class ___. Mockito can only mock non-private & non-final classes
even if the class is non-private (protected), non-final and non-static.How to reproduce it
1.- Delete this from the pom.xml file
<forkMode>always</forkMode>
2.- Run
mvn package
in the command lineStacktrace
The text was updated successfully, but these errors were encountered: