开发者

How to create Mock objects for Android Activities (Junit)

开发者 https://www.devze.com 2023-03-27 01:22 出处:网络
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 pop

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?


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 refere to the developer guide under Create a Local Unit Test Class heading, you will find the answer to your question. Also refer to the "Mock Android Dependecies" sub heading on the same page.

0

精彩评论

暂无评论...
验证码 换一张
取 消