Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well unit testing is a method by which individual units of source code are tested to determine if they are fit for use. So when you say you want to test your custom view, you can check various methods of your custom views like "onTouchEvent", "onDown", "onFling", "onLongPress", "onScroll", "onShowPress", "onSingleTapUp", "onDraw" and various others depending on your business logic. You can provide mock values and test it. I would suggest two methods of testing your custom view.</p> <p><strong>1) Monkey Testing</strong> Monkey testing is random testing performed by automated testing tools. A monkey test is a unit test that runs with no specific test in mind. The monkey in this case is the producer of any input. For example, a monkey test can enter random strings into text boxes to ensure handling of all possible user input or provide garbage files to check for loading routines that have blind faith in their data. This is a black box testing technique and it can check your custom view in so many unique conditions that you will get astonished :) . </p> <p><strong>2) Unit Testing</strong></p> <p><strong>2a) Use Robotium Unit Testing Framwork</strong></p> <p>Go to Robotium.org or <a href="http://code.google.com/p/robotium/" rel="noreferrer">http://code.google.com/p/robotium/</a> and download the example test project. Robotium is a really easy to use framework that makes testing of android applications easy and fast. I created it to make testing of advanced android applications possible with minimum effort. Its used in conjunction with ActivityInstrumentationTestCase2.</p> <p><strong>2b) Use Android Testing Framework</strong></p> <p>Here are the links to the reference: <a href="http://developer.android.com/reference/android/test/ActivityInstrumentationTestCase2.html" rel="noreferrer">http://developer.android.com/reference/android/test/ActivityInstrumentationTestCase2.html</a> and <a href="http://developer.android.com/reference/android/test/ActivityUnitTestCase.html" rel="noreferrer">http://developer.android.com/reference/android/test/ActivityUnitTestCase.html</a></p> <p>For starters: <a href="http://developer.android.com/guide/topics/testing/testing_android.html" rel="noreferrer">http://developer.android.com/guide/topics/testing/testing_android.html</a></p> <blockquote> <p>According to one user : Aside from easily testing non platform dependent logic I haven't found a clever way to run tests, so far (at least for me) any actual platform logic testing is cumbersome. It's almost non trivial anyway because I've found differences in implementation between the emulator and my actual device and I hate to run a unit test implementation on my device just to remove the application afterwards.</p> <p>My strategy has been: Try to be concise and make the logic well thought out and then test implementation piece by piece (less then desirable).</p> </blockquote> <p><strong>Also Stephen Ng provides good aproach for real Unit Test for Android projects solution: <a href="https://sites.google.com/site/androiddevtesting/" rel="noreferrer">https://sites.google.com/site/androiddevtesting/</a></strong></p> <blockquote> <p>One user has made a screencast.</p> <p><strong>Here's a ScreenCast I made on how I got Unit Tests to work. Simple Unit Tests and more complex unit tests that depend on having a reference to Context or Activity objects. <a href="http://www.gubatron.com/blog/2010/05/02/how-to-do-unit-testing-on-android-with-eclipse/" rel="noreferrer">http://www.gubatron.com/blog/2010/05/02/how-to-do-unit-testing-on-android-with-eclipse/</a></strong></p> </blockquote> <p>Hope it helps you testing your custom view in all possible conditions :)</p> <hr> <p><strong>Comment (futlib) All your suggestions seem to involve testing the ACTIVITY, while I really want to test just the VIEW. I might want to use this view in other activities, so it doesn't make much sense for me to test it with a specific one. – futlib</strong></p> <blockquote> <p>Answer: To implement a custom view, you will usually begin by providing overrides for some of the standard methods that the framework calls on all views. For example "onDraw", "onKeyDown(int, KeyEvent)", "onKeyUp(int, KeyEvent)", "onTrackballEvent(MotionEvent)" etc of your custom view. So when you want to do unit testing for your custom you'll have to test these methods, and provide mock values to it so that you can test your custom view on all possible cases. Testing these methods doesn't mean that you are testing your ACTIVITY, but it means testing your custom view (methods/functions) which is within an activity. Also you'll have to put your custom view in an Activity eventually for your target users to experience it. Once thoroughly tested , your custom view can be placed in many projects and many activities.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload