A
A
AgranatMarkQuestioner2017-05-10 14:52:11
Mobile development
AgranatMarkQuestioner, 2017-05-10 14:52:11

Who mocks in swift, and how to test services?

I write tests for services, in addition to the fact that the tests themselves turn out to be cumbersome due to the fact that the service uses 5-6 objects ( networking, urlProvider, networkingMapper, objectMapper, responseStatusHandler), it is also necessary to write mocks for each of these objects (I you need to mock both classes and structures). Does anyone know if there is a framework similar to mockito where you don't have to write your own mocks. All I found out is that Swift supports read-only reflection, which does not allow you to change the behavior of an object at runtime, therefore you cannot write such a lib.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav Beltyukov, 2017-05-18
@AgranatMarkQuestioner

Unfortunately, it is impossible to create a mock at runtime in swift :( moreover, the behavior of the structure cannot be changed in any way. Therefore, we use 2 things:
1. Dependencies are specified everywhere through protocols
2. Mocks cannot be slipped at runtime, but can be generated at the build stage using Sourcery This tool helps to generate code automatically from templates.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question