界面模拟工作不正常

时间:2018-06-08 14:30:26

标签: java unit-testing testing mockito

我正在编写测试并尝试模拟IMyResponse接口。但它在嘲笑之后返回int。这是我的工作:

public interface IMyResponse extends Serializable {
    // ...
    Object getResponseObject();
}

private IMyResponse myResponse;

@Before
public void setUp(){
    myResponse = mock(IMyResponse.class);
}

@Test
public void mockTest(){
    // myResponse.getResponseObject() is 0
    when(myResponse.getResponseObject()).thenReturn("value");
    // myResponse.getResponseObject() is 46
}

我做错了什么?

1 个答案:

答案 0 :(得分:1)

改变了mockito版本帮助(它是1.10):

androidTestImplementation 'org.mockito:mockito-android:2.15.0'