Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Mock objects for Android Activities (Junit)

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?

like image 547
thunderousNinja Avatar asked Aug 09 '11 20:08

thunderousNinja


People also ask

How do you make a mock object in JUnit?

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.

What is mock object in Android?

A mock object is the object that has properties of the real object while skipping the complications of creating a real object now.


1 Answers

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.

like image 55
lethargicpanda Avatar answered Oct 12 '22 22:10

lethargicpanda