Cannot mock concrete classes with Mockito
See original GitHub issueI’m getting
java.lang.NoClassDefFoundError: com/android/dx/stock/ProxyBuilder
or
java.lang.ExceptionInInitializerError
when I try to mock a concrete class on dexmaker 1.4 or 1.3. Reverting to 1.2 from google code works fine.
java.lang.NoClassDefFoundError: com/android/dx/stock/ProxyBuilder
at com.android.dx.mockito.DexmakerMockMaker.createMock(DexmakerMockMaker.java:56)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:33)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:59)
at org.mockito.Mockito.mock(Mockito.java:1285)
at org.mockito.Mockito.mock(Mockito.java:1163)
at lt.segfoltas.asthmacontroltest.DbAsyncTests.setUp(DbAsyncTests.java:28)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1584)
java.lang.ExceptionInInitializerError
at com.android.dx.mockito.DexmakerMockMaker.createMock(DexmakerMockMaker.java:56)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:33)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:59)
at org.mockito.Mockito.mock(Mockito.java:1285)
at org.mockito.Mockito.mock(Mockito.java:1163)
at lt.segfoltas.asthmacontroltest.DbAsyncTests.setUp(DbAsyncTests.java:28)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1584)
Caused by: java.lang.ExceptionInInitializerError
at com.android.dx.stock.ProxyBuilder.<clinit>(ProxyBuilder.java:758)
... 15 more
Caused by: java.lang.NoClassDefFoundError: com.android.dx.rop.type.Type
at com.android.dx.TypeId.<clinit>(TypeId.java:36)
... 16 more
Mocking interfaces works as before. I’d just use 1.2, but I hit #12 on lollipop.
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Mocking Chained calls in Concrete Class Mockito
Mockito is not able to mock out final classes. There are a few ways to get around this. 1) In MyAbstractClass consider not...
Read more >Mocking concrete class - Not recommended
I've just read an excerpt of "Growing Object-Oriented Software" book which explains some reasons why mocking concrete class is not recommended.
Read more >Mock Final Classes and Methods with Mockito - Baeldung
In this short tutorial, we'll focus on how to mock final classes and methods using Mockito. As with other articles focused on the...
Read more >A Unit Testing Practitioner's Guide to Everyday Mockito - Toptal
Mockito mocks not only interfaces but also abstract classes and concrete non-final classes. Out of the box, Mockito cannot mock final classes and...
Read more >Installation - EasyMock
Finally, since EasyMock 4.1, JUnit 5 extensions are supported. ... the type of the concrete class can't be checked statically against the mock...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It turns out that all I was missing is a dependency on the new(?)
dexmaker-dx
module. This is a new requirement in 1.3/1.4, but hasn’t been mentioned anywhere that I’ve seen.Closing this one as a duplicate of #22