我正在尝试使用mockito在androidstudio中对方法调用进行单元测试。是这样的:
public static class DeviceMessageHandler extends Handler {
public DeviceMessageHandler(Looper looper) {
super(looper);
}
@Override
public void handleMessage(Message msg) {
try {
switch (msg.what) {
default:
String message = (String) msg.obj;
DeviceRequest deviceRequest = new Gson().fromJson(message, DeviceRequest.class);
String requestType = deviceRequest.getKey();
if (DeviceMessage.SOME_ACTION.equals(requestType)) {
sendResponseWithMessage(execId, COMMAND_STATE, "Not accepted");
}
}
}
}
}
public static void sendResponseWithMessage(String execId, String commandState, String reasonIfAny) {
// do some work
} catch (Exception e) {
e.printStackTrace();
}
}
所以在这里我可以打电话给sendresponsewithmessage。我想检查调用此方法时传递的参数。问题是它是一个静态方法,我不知道如何捕获传递给静态方法的参数。我试过使用powermock,但由于这是一个android项目,我不能使用powermock。有什么方法可以用期望值Assert传递给方法调用的参数吗?
1条答案
按热度按时间qlckcl4x1#
对于我来说,在android中运行powermock很管用: