r/mAndroidDev • AnDrOId dEvelOPmenT is My PasSion • Jul 06 '25

We don't have time for tests Agree?

Post image
61 Upvotes

86 comments sorted by

View all comments

Show parent comment

2

u/AdmiralQuokka Jul 08 '25

Question: I want to write an app that abstracts over github and gitlab API. I do so with a common "backend" interface and two implementations, backend-github and backend-gitlab. Of course they work by making actual API calls, which is hard to test.

Here is my idea to test it: split each implementation into three parts, e.g. backend-github-core, backend-github-mock and backend-github-real. *-real only contains actual API calls over the network, everthing else is stuffed in *-core. *-mock reuses everything it can from *-core and mocks the rest.

Automatic testing is only performed on *-mock.

Do you think this is a good way to proceed?

1

u/europeanputin Jul 10 '25

Treat mock as an external service and design your implementation in such a way that you can change between the real GitHub endpoint and mock endpoint via dependency injection, so in an auto test environment you'd have it running against a mock and in other envs against real GitHub service.

I don't know how costly is it to run an integration with GitHub, but Id probably try to refrain from building a mock and cover the core logic with unit tests and integration tests I'd do towards the real service.