Robolectric is a great tool to test classes that depend on Android views and classes properly. I use Robolectric heavily to test custom view logic.
I wrote a custom view to mimic TextInputLayout with some added app specific features. I also did the hint to label and label to hint animation in the custom view to mimic this.
So I have a
showLabel() method which animates hint to label text and
hideLabel() method which animates label to text.
So our naive test class for this view would look like this.
As mentioned in the comment, the assertions…
We can all relate to how annoying it might be to hit the “run” button in Android Studio, only to find yourself having to wait for a while for the emulator to generate, load, and build your project. Thankfully, testing libraries and frameworks have been created to prevent us from doing this all the time. Continuing from my previous guide where we looked at the basics of Android testing, we’ll now be looking at how to set up Robolectric in your project and use it to write unit tests!
The very first thing you’ll need to do, as with all…
Have you ever felt boring when you have to run your app for a small little change to see it is working fine or not?
If yes then, you must try Robolectric, it is a unit testing framework that allows Android applications to be tested on the JVM without an emulator or device.
These are the main features of it:
The (retired) Pub(lication) for Android & Tech, focused on Development