Unit Tests with Mockito and Jacoco in The Main Android Architectures — MVC, MVP, MVVM, VIPER, MVI, Clean — part 6: Clean

André Figas
3 min readOct 24, 2022

--

Clean

If you have some doubts about this architecture, check my other article.

Just like a brief, the main change to be done when you adopt a clean architecture, if you come from any MV* (MVP, MVC, MVVM…) Architecture, will be done in what these architectures define as a Model Layer.

So, as we did in MVI, here you have to choose some architecture to combine, like MVC+Clean, MVP+Clean, MVVM+Clean, VIPER+Clean, MVI+MVP+Clean and etc.

Mappers

Here we just checked if our conversion really worked as this is supposed.

UseCases

Our use cases depend on the repository. So we had to create a mock instance of that and define what the method, that e wish to validate, will return.

Repository

I do not have a failure implementation here, because I did not write any logic to generate an error here. It does not mean my call could not produce an error, but a do not have a logic written by me to be tested.
But, as you saw, when I tested use cases a cared about the error possibility. Note our use cases depend on PersonRepoContract, not necessarily this implementation (PersonRepository), so there we have to be prepared for all possibilities.

Since on MVC, here we only tested the Model layer, so I guess It would be the perfect sample to demonstrante a couple of reports here. I won’t put all architectures combinations here, but you can check it on GitHub.

There are all clean build variants: mvc_clean, mvp_clean, mvvm_clean, viper_clean, mvi_with_presenter_clean, mvi_with_viewmodel_clean, mvi_with_viper_clean

Generating Test Results Report

./gradlew app:testMvc_clean_UnitTest

Output

app/build/reports/tests/testMvc_clean_UnitTest/index.html

Generating Coverage Report

./gradlew app:testMvc_clean_UnitTestCoverage

Output

app/build/reports/jacoco/testMvc_clean_UnitTestCoverage/index.html

--

--