Bug in Mockito with Grails/Groovy

后端 未结 1 1313
广开言路
广开言路 2021-01-18 08:07

I am using Mockito 1.9 with Grails 1.3.7 and I have a strange bug.

The following test case in java works:

im         


        
相关标签:
1条回答
  • 2021-01-18 08:24

    The problem is Groovy is intercepting your method call before it reaches someVoidMethod. The method actually being called is getMetaClass which is not a void method.

    You can verify this is happening by replacing:

    doNothing().when(testClassMock).someVoidMethod()
    

    with:

    doReturn(testClassMock.getMetaClass()).when(testClassMock).someVoidMethod()
    

    I'm not sure you will be able to get around this issue using stock Mockito and Groovy.

    0 讨论(0)
提交回复
热议问题