Cartesian Theater
Cartesian Theater

Reputation: 1970

Android -- Unable to resolve activity in JUnit test only for some activities

When I run a JUnit test for one of my activities I get the above error, but not for another activity. Both activities are in the same package.

Here's my barebones code for activity that doesn't work. (the one that does work is the same, just switch the activity name).

public class CounterTest extends ActivityInstrumentationTestCase2<Reward>{

Activity mActivity;


public CounterTest() {
    super("com.morningsun.caffeinecounter", Reward.class);

}

@Override
protected void setUp(){
    try{
    super.setUp();
    mActivity = this.getActivity();


    }catch(Exception e){
        e.printStackTrace();
    } 


}

public void test(){

    Assert.assertTrue(1==1);

}

And here's my manifest instrumentation info

`

    <<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.missaion.caffeinecounter.test"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />
    <instrumentation 
        android:targetPackage="com.morningsun.caffeinecounter" 
        android:name="android.test.InstrumentationTestRunner" />
    <application android:icon="@drawable/icon" android:label="@string/app_name">

    <uses-library android:name="android.test.runner" />
    </application>
</manifest>


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        android:installLocation="auto"
        package="com.morningsun.caffeinecounter"
        android:versionCode="2"
         android:versionName="1.05">

    <uses-sdk android:minSdkVersion="7" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.VIBRATE" />

    <application 
        android:icon="@drawable/icon" 
        android:label="@string/Title">

        <activity android:name=".CaffeineCounterActivity"
                  android:label="@string/Title"
                  android:launchMode="singleTask">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>
        </activity>


        <activity 
            android:name=".DrinkSelector"
            android:theme="@android:style/Theme.Dialog"
            android:noHistory="true" 
            android:label="@string/Select"  />  

        <activity 
            android:name=".Plot"    
            android:noHistory="true" 
            android:label="@string/PlotData"  />  

        <activity 
            android:name=".Info"    
            android:noHistory="true" 
            android:label="@string/InfoText"  />  

          <activity 
            android:name=".SendDialog"
            android:theme="@android:style/Theme.Dialog"
            android:noHistory="true" 
            android:label="@string/SaveFile"  />    


        <activity 
            android:name=".DrinkDialog"
            android:theme="@android:style/Theme.Dialog"
            android:noHistory="true"
            android:label="@string/AddDrink"  />

        <activity 
            android:name=".DrinkDialogNonLinear"
            android:theme="@android:style/Theme.Dialog"
            android:noHistory="true"
            android:label="@string/AddDrink"  />

        <activity 
            android:name=".EditType"
            android:theme="@android:style/Theme.Dialog"
            android:noHistory="true"
            android:label="@string/EditType"  />

        <activity 
            android:name=".EditTypeStarbucks"
            android:theme="@android:style/Theme.Dialog"
            android:noHistory="true" 
            android:label="@string/Select"  />  

        <activity 
            android:name=".DrinkUpdater"
            android:theme="@android:style/Theme.Dialog"
            android:noHistory="true"
            android:label="@string/EditDrink"  />



        <activity 
            android:name=".AmountDialog"
            android:theme="@android:style/Theme.Dialog"
            android:noHistory="true" />

          <activity 
            android:name=".NewTypeDialog"
            android:theme="@android:style/Theme.Dialog"
            android:noHistory="true" 
            android:label="@string/AddType" />



        <activity 
            android:name=".DayList"
            android:label="@string/DateList"/>

         <activity 
            android:name=".TypeList"
            android:theme="@android:style/Theme.Dialog"
            android:label="@string/Types"/>


         <activity 
            android:name=".DayDrinkList"
            android:label="@string/DateDrinkList">

        </activity>

        <activity 
            android:name=".SodaList"
            android:theme="@android:style/Theme.Dialog"
            android:noHistory="true"
            android:label="@string/SelectDrink"  />

         <activity 
            android:name=".LimitDialog"
            android:theme="@android:style/Theme.Dialog"
            android:noHistory="true" />



    </application>
</manifest>

The other posts on this topic say to check the instrumentation targetPackage and to check the values in the constructor super, which seem okay to me. Any help would be appreciated.

Here are the error messages:

03-30 13:35:08.853: W/System.err(1727): java.lang.RuntimeException: Unable to resolve activity for: Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.morningsun.caffeinecounter/.Reward }
03-30 13:35:08.853: W/System.err(1727):     at android.app.Instrumentation.startActivitySync(Instrumentation.java:371)
03-30 13:35:08.863: W/System.err(1727):     at android.test.InstrumentationTestCase.launchActivityWithIntent(InstrumentationTestCase.java:119)
03-30 13:35:08.863: W/System.err(1727):     at android.test.InstrumentationTestCase.launchActivity(InstrumentationTestCase.java:97)
03-30 13:35:08.863: W/System.err(1727):     at android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumentationTestCase2.java:98)
03-30 13:35:08.863: W/System.err(1727):     at com.missaion.caffeinecounter.test.CounterTest.setUp(CounterTest.java:33)
03-30 13:35:08.863: W/System.err(1727):     at junit.framework.TestCase.runBare(TestCase.java:125)
03-30 13:35:08.863: W/System.err(1727):     at junit.framework.TestResult$1.protect(TestResult.java:106)
03-30 13:35:08.863: W/System.err(1727):     at junit.framework.TestResult.runProtected(TestResult.java:124)
03-30 13:35:08.863: W/System.err(1727):     at junit.framework.TestResult.run(TestResult.java:109)
03-30 13:35:08.863: W/System.err(1727):     at junit.framework.TestCase.run(TestCase.java:118)
03-30 13:35:08.863: W/System.err(1727):     at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
03-30 13:35:08.863: W/System.err(1727):     at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
03-30 13:35:08.863: W/System.err(1727):     at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:520)
03-30 13:35:08.863: W/System.err(1727):     at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)

Upvotes: 3

Views: 3595

Answers (1)

Code-Apprentice
Code-Apprentice

Reputation: 83577

The Reward class which you are testing is not listed in the manifest that you posted. Double-check that you have an <activity> tag for this class.

Upvotes: 3

Related Questions