私は2つのアクティビティを使用する小さなアプリケーションを持っています。どちらのアクティビティもMapActivityを継承し、マップ(com.google.android.maps)を表示します。 AndroidのGoogleマップドキュメント以来AndroidでUnit Testを実行すると、インテントが別のプロセスに解決される
は
つだけMapActivityが プロセスごとにサポートされると言います。同時に複数のMapActivities が実行されている可能性があります。 予期しない望ましくない方法で干渉します 方法。
私は2つの異なるプロセス(私はそれを短くするためにいくつかの行を削除した)で2つのアクティビティを実行するために、私のマニフェスト修正:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light">
<uses-library android:name="com.google.android.maps" />
<activity
android:name=".Activity1"
android:process=".Activity1">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>Unit
</activity>
<activity
android:name=".Activity2"
android:process=".Activity2">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>
これでアプリケーションは正常に動作しますが、ときに私は何が問題を抱えています両方のアクティビティで単体テストを実行します。たとえば :私はgetActivity()
メソッドを呼び出すと
package com.example.myapp;
public class Activity1Test extends ActivityInstrumentationTestCase2<Activity1> {
Activity1 mActivity;
public Activity1Test() {
super("com.example.myapp.Activity1", Activity1.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
setActivityIntent(new Intent());
mActivity = getActivity(); //An exception is thrown at this line
}
}
例外がスローされます。
java.lang.RuntimeException: Intent in process com.example.myapp resolved to different process .Activity1: Intent { flg=0x10000000 cmp=com.example.myapp/.Activity1 }
at android.app.Instrumentation.startActivitySync(Instrumentation.java:377)
at android.test.InstrumentationTestCase.launchActivityWithIntent(InstrumentationTestCase.java:119)
at android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumentationTestCase2.java:100)
at com.example.myapp.Activity1Test.setUp(Activity1Test.java:28)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:520)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)
は正しいプロセスを「解決」するためにユニットテストを作成する方法はありますか?
ありがとう、チャートは明らかです。 それでは、Instrumentationはすべて同じプロセスで実行され、その後いくつかのコードは '.Activity1'を処理するためにエスケープしようとします。はいの場合は、マルチ処理を維持し、単体テストの実行時にこの設定を無視するように計測を依頼する方法がありますか? – Michele