I am fairly new to unit testing, in android specifically. I have written an application with numerous activities. However, some of these activities rely on certain objects for them to populate the activity's views. I guess my question is: Is there a way I can mock up the objects within the Activity and make the activity use that created mock object from my Junit tests? Thanks in advance, I cant find the solution for this anywhere?
We can use Mockito class mock() method to create a mock object of a given class or interface. This is the simplest way to mock an object. We are using JUnit 5 to write test cases in conjunction with Mockito to mock objects.
A mock object is the object that has properties of the real object while skipping the complications of creating a real object now.
You can also take a look at AndroidMock:
http://code.google.com/p/android-mock/wiki/UsingAndroidMock
It is a Mock Objects framework for Android build on top of EasyMock.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With