在android测试中模拟Gson()。toJson

时间:2018-06-12 13:02:33

标签: java android mockito gson android-testing

我正在为有活动的活动创建一个测试:

Logger.i("Response", new Gson().toJson(response));

它与消息崩溃:

java.lang.UnsupportedOperationException: Attempted to serialize java.lang.Class: web.services.Response. Forgot to register a type adapter?

我尝试将以下行添加到测试中,但它没有帮助:

Gson gson = new GsonBuilder().registerTypeAdapter(mock(Response.class).getClass(), new ClassTypeAdapter()).create();

P.S。我不能用powerMock来模拟Gson的最后一堂课。 如何解决这个问题?

0 个答案:

没有答案