Issue
I have go through Test Android Apps in Android document. Google introduced AndroidX testing, but I am still very of confused of its implications.
I am using MVVM Android architecture components with ViewModel, LiveData.
Which parts of the Android X Framework do I need to use?
View(Activity.Fragments) --> Espresso?
ViewModel(with LiveData) --> RoboElectric?
Model --> JUnit or RoboElectric?
Why is Google still confusing us with lot of libraries, why can't they move all Local test, Instrumentation test, and everything under the same Framework(Espresso)?
Solution
The Google Testing team has made many improvements to their testing framework AndroidX.
Why Google still confusing with lot of libraries, why cant they move all Local test, Instrumentation test everything under same Framework(Espresso)?
With AndroidX Test, they are actually attempting to solve this!
First off, regular "Junit" unit Tests are unchanged. You should test your java code on the JVM the same way you were doing.
But now, with AndroidX, they have made the Robolectric 4.0 API the same as Espresso's so it is now possible to run your Espresso Tests as Robolectric tests. This means when developing locally, you can iterate more quickly because the Instrumentation Tests can run so much faster instead of having to run on emulators. It also makes it a lot easier to learn Robolectric, because you are able to use the same API as espresso.
When you get to the PR or CI phase, you can then submit those same tests that ran on Robolectric JVM to run on your CI on real devices using Espresso.
I suggested checking out Testing Rebooted (with AndroidX Test) (Android Dev Summit '18) for more context.
In this picture, the failing UI and Unit tests would represent the same test but represented as Espresso/Robolectric Instrumentation Test depending on what you want to run and when. For clarity, you would want to run it as Robolectric when you are doing local development especially with TDD. When ready to submit a PR, you can then run the same test on CI with emulator or real device.
So, while AndroidX.test can be confusing, I suggest watching this video to get a bit more of a grasp on Google's intent with the framework.
Also, I agree they can be providing more examples and guidance on using the new Androidx.Test!
Answered By - Mark Han

0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.