Activityユニットテストエラー

2548 ワード

今日Activityユニットのテストタイムズで次のエラーが発生しました.
java.lang.RuntimeException: Unable to resolve activity for: Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.unit.test/.demo.MainActivity }
at android.app.Instrumentation.startActivitySync(Instrumentation.java:375)
at android.test.InstrumentationTestCase.launchActivityWithIntent(InstrumentationTestCase.java:119)
at android.test.InstrumentationTestCase.launchActivity(InstrumentationTestCase.java:97)
at android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumentationTestCase2.java:104)
at com.unit.test.junit.MainActivityTest.setUp(MainActivityTest.java:26)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1619)

コードは次のとおりです.
package com.unit.test.junit;

import com.unit.test.R;
import com.unit.test.demo.MainActivity;

import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.TextView;

public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> {
	private Activity activity = null;
	private TextView titleTxtv = null;

	public MainActivityTest() {
		super(MainActivity.class);
		// TODO Auto-generated constructor stub
	}

	/**
	 *  
	 */
	@Override
	protected void setUp() throws Exception {
		super.setUp();
		setActivityInitialTouchMode(false);
		activity = getActivity();
	}

	/**
	 *  
	 */
	@Override
	protected void tearDown() throws Exception {
		super.tearDown();
	}

	/**
	 *  
	 */
	public void testTemp001() {
		titleTxtv = (TextView) activity.findViewById(R.id.txt_welcome);
		assertEquals(activity.getString(R.string.welcome_msg), titleTxtv.getText());
	}

}

理由:登録ファイルに登録されていません.以下のように登録すればいいです.
<activity
            android:name="com.unit.test.demo.MainActivity"
            android:configChanges="orientation|keyboardHidden"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustResize" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>