当我为我的一个活动运行 JUnit 测试时,我得到了上述错误,但不是另一个活动。这两个活动都在同一个包中。
这是我不起作用的活动的准系统代码。(起作用的是一样的,只是切换活动名称)。
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);
}
这是我的清单仪表信息
`
<<?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>
关于这个主题的其他帖子说检查检测 targetPackage 并检查构造函数 super 中的值,这对我来说似乎没问题。任何帮助,将不胜感激。
以下是错误消息:
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)