I\'m writing tests for a component in my Android application. This component uses activities to make some reports. So I need an activity in order to test the component (ugly
Yes, it is possible but not recommended, as it stated in the official dev guide:
Once you have created a test project, you populate it with a test package. This package does not require an Activity, although you can define one if you wish. Although your test package can combine Activity classes, test case classes, or ordinary classes, your main test case should extend one of the Android test case classes or JUnit classes, because these provide the best testing features.
In order to do this, you need:
Suppose I have a Test Project com.example.test contain two class DummyActivity and DummyActivityTest, then if you want test DummyActivity using DummyActivityTest, you need to define your Test Project's AndroidManifest.xml like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<!-- targetPackage point to test project itself -->
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.test" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="android.test.runner" />
<activity
android:name=".DummyActivity"
android:label="@string/app_name" >
</activity>
</application>
The test project and activity can coexist together, put the target package name as the test project's package name