unit testing - Android: How to test a custom view? -


there several methods of unit testing in android, what's best 1 testing custom view i've written?

i'm testing part of activity in instrumentation test case, i'd rather test view, isolated.

well unit testing method individual units of source code tested determine if fit use. when want test custom view, can check various methods of custom views "ontouchevent", "ondown", "onfling", "onlongpress", "onscroll", "onshowpress", "onsingletapup", "ondraw" , various others depending on business logic. can provide mock values , test it. suggest 2 methods of testing custom view.

1) monkey testing monkey testing random testing performed automated testing tools. monkey test unit test runs no specific test in mind. monkey in case producer of input. example, monkey test can enter random strings text boxes ensure handling of possible user input or provide garbage files check loading routines have blind faith in data. black box testing technique , can check custom view in many unique conditions astonished :) .

2) unit testing

2a) use robotium unit testing framwork

go robotium.org or http://code.google.com/p/robotium/ , download example test project. robotium easy use framework makes testing of android applications easy , fast. created make testing of advanced android applications possible minimum effort. used in conjunction activityinstrumentationtestcase2.

2b) use android testing framework

here links reference: http://developer.android.com/reference/android/test/activityinstrumentationtestcase2.html , http://developer.android.com/reference/android/test/activityunittestcase.html

for starters: http://developer.android.com/guide/topics/testing/testing_android.html

according 1 user : aside testing non platform dependent logic haven't found clever way run tests, far (at least me) actual platform logic testing cumbersome. it's non trivial anyway because i've found differences in implementation between emulator , actual device , hate run unit test implementation on device remove application afterwards.

my strategy has been: try concise , make logic thought out , test implementation piece piece (less desirable).

also stephen ng provides aproach real unit test android projects solution: https://sites.google.com/site/androiddevtesting/

one user has made screencast.

here's screencast made on how got unit tests work. simple unit tests , more complex unit tests depend on having reference context or activity objects. http://www.gubatron.com/blog/2010/05/02/how-to-do-unit-testing-on-android-with-eclipse/

hope helps testing custom view in possible conditions :)


comment (futlib) suggestions seem involve testing activity, while want test view. might want use view in other activities, doesn't make sense me test specific one. – futlib

answer: implement custom view, begin providing overrides of standard methods framework calls on views. example "ondraw", "onkeydown(int, keyevent)", "onkeyup(int, keyevent)", "ontrackballevent(motionevent)" etc of custom view. when want unit testing custom you'll have test these methods, , provide mock values can test custom view on possible cases. testing these methods doesn't mean testing activity, means testing custom view (methods/functions) within activity. you'll have put custom view in activity target users experience it. once thoroughly tested , custom view can placed in many projects , many activities.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -