Closed scottkennedy closed 7 years ago
I'm not sure I understand what you are trying to achieve or what is lacking?
You can try to replicate the logic inside server response body parser https://github.com/apollographql/apollo-android/blob/master/apollo-runtime/src/main/java/com/apollographql/apollo/internal/interceptor/HttpResponseBodyParser.java#L36
where you replace response.body().source()
with json string
@sav007 What about the case where I don't want to mock an entire query? For example, what if I want to just want to deserialize some fragment with some JSON and use that in my test? Is there any way to do that?
Can you use mockito?
On Sep 11, 2017 8:31 PM, "Mandeep Singh" notifications@github.com wrote:
@sav007 https://github.com/sav007 What about the case where I don't want to mock an entire query? For example, what if I want to just want to deserialize some fragment with some JSON and use that in my test? Is there any way to do that?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/apollographql/apollo-android/issues/653#issuecomment-328696318, or mute the thread https://github.com/notifications/unsubscribe-auth/AEUX3Dw9_syrDoU9RDiNbZy_yh0q7B9mks5shdDLgaJpZM4PRh9H .
Mocking a JSON model is a lot of effort, I would rather use JSON and deserialize my models from that
@mandrizzle any model generated by Apollo including fragments, has a Mapper
class, that can be used to deserialize from JSON. It has one method map(ResponseReader)
where response reader can be custom implementation that backed by string json.
Do you have any example of a customer reader?
I don't have right now, but will come up with smth later this week
Guys thanks a lot for this. You've saved a me a lot of effort in my unit tests.
I'm trying to write some unit tests where I need the model objects, but there doesn't seem to be a way of doing this without setting up a mock server that takes in a request, which is a lot of overhead for a unit test.