-
-
Notifications
You must be signed in to change notification settings - Fork 690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Contributor needed] UI testing with ViewModels #48
Comments
Test project where want to try it first: https://github.com/dGorod/test_500px_api_kotlin |
Hello, this is one the The article you mention deals about unit testing (testing before the UI) - Which is (in my point of view) essential to do before making any UI test. I'll put that on top priority. |
Hi, For insert mock objects under Espresso I am essentially configuring the tests for use another "Application" class for start. That use another startKoin(..) method, that calls our TestModules in place of the modules for the Real app. (This imply make some methods open, and probably will be improved.) Configurations and Code: Gradle:
and I add the library androidTestCompile 'com.linkedin.dexmaker:dexmaker-mockito:2.12.1' Custom AndroidJUnitRunner under the folder of the espresso tests:
Our application for tests:
My TestModule looks like:
So, I can set the Authenticator with the mock I want for the Espresso tests. # RELATED TO THE UNIT TESTS: What I do is create a TestModule: (Extends for Module and not for AndroidModule in this context) and startKoin into the tests with this modules.
Test example: we are using startKoin on koin context, just need the list of modules.
I am using kotlintest. And I can insert mocks :) Thanks for all, And tell me please if something is not clear. I have experience in development but I am very new sharing my knowledge hahaha so Just tell me and I can improve :) |
Interesting 👍 |
You could just change your myTestModule, for instance instead of assigning a mock to the petRepository, just changes the provide method to a 'mock(PetRepository::class.java) as PetRepository' or if you're using mockito-kotlin just mock<PetRepository>() |
In fact, Koin is already compatible with Android instrumented espresso tests. Just need precise explanation on what and how to do things |
Instrumented test are compatible |
I couldn't find any documentation around Espresso testing or any samples - are these in the works? |
You can find espresso/room tests in https://github.com/InsertKoinIO/koin/tree/1.0.0/koin-projects/examples/android-mvvm/src/androidTest/java/fr/ekito/myweatherapp Just use the A good article https://proandroiddev.com/testing-with-koin-ade8a46eb4d |
In addition to @mataiaslev answer, my project is using
To fix this error, add exclude
|
Hello, @arnaudgiuliani !
Thank you for a great DI library. Starting using it and need some help with testing.
I have Android project with architecture components. I inject ViewModel using lazy 'by viewModel()' method. Inside ViewModel I have a repository that goes to API. Now I want to write UI tests for my app using Espresso. Obviously, I don't need real calls to the Internet, I want mocked data returned using Mockito.
And now I'm confused in what direction I should go. I read article about testing in documentation. But still can't figure out how to inject mocked repository inside my ViewModel for Espresso test.
Will appreciate any help.
Thanks.
The text was updated successfully, but these errors were encountered: