The AndroidTestCase base class
This class can be used as a base class for general-purpose Android test cases.
Use it when you need access to Android resources, databases, or files in the filesystem. Context is stored as a field in this class, which is conveniently named mContext
and can be used inside the tests if needed, or the getContext()
method can be used too.
Tests based on this class can start more than one Activity using Context.startActivity()
.
There are various test cases in Android SDK that extend this base class:
ApplicationTestCase<T extends Application>
ProviderTestCase2<T extends ContentProvider>
ServiceTestCase<T extends Service>
When using the AndroidTestCase
Java class, you inherit some base assertion methods that can be used; let's look at these in more detail.
The assertActivityRequiresPermission() method
The signature for this method is as follows:
public void assertActivityRequiresPermission(String packageName, String className, String permission)