Spy object by Mockito in Spring

后端 未结 4 477
眼角桃花
眼角桃花 2020-12-20 17:56

When I try to Spy an object in my unit test, I got an exception. This is my unit test file:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loc         


        
4条回答
  •  囚心锁ツ
    2020-12-20 18:53

    In the release 2.0.32-beta Mockito team moved cglib classes into separated jar. But PowerMock still depends on classes which have been moved, so you get java.lang.NoClassDefFoundError.

    In release 1.6.2 Mockito classes was copied into PowerMock, but not all. As workaround I may suggest clone, build and add to classpath the mockito-cglib (https://github.com/mockito/mockito-cglib).

    The PowerMock will have supported Mockito 2 API since 1.6.5 which will have been released by the end of the May, but will still use cglib. The full Mockito 2 with Bytebuddy will be supported in release after 1.6.5.

    Developer Guide for Migration to Mockito 2

提交回复
热议问题