Android: How to test a custom view?

futlib picture futlib · Feb 6, 2011 · Viewed 18.1k times · Source

There are several methods of unit testing in Android, what's the best one for testing a custom view I've written?

I'm currently testing it as part of my activity in an instrumentation test case, but I'd rather test just the view, isolated.

Answer

adam picture adam · Mar 23, 2011

A simple solution for the lack of a View-focused TestCase implementation would be to create a simple Activity within your test project that includes your view. This will allow you to write tests against the view using a simple Activity. Information on Activity testing:

http://developer.android.com/reference/android/test/ActivityUnitTestCase.html