2012-01-13 5 views
4

アンドロイドでインストラクションテストを実行しようとするとエラーが発生します。私はというAudioPlayerActivityという名前のアクティビティを、com.mycompany.mobile.android.guiというパッケージに入れました。そのプロジェクトのGUIをテストしようとしていますが、私は次のエラーで実行しています。 :アクティビティを解決できません:インストゥルメンテーションテストのアンドロイドアクティビティの意図

java.lang.RuntimeException: Unable to resolve activity for: Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.mycompany.mobile.android.gui/.AudioPlayerActivity }

私はthis questionを読み、そこアドバイスに従ったが、無駄にしています。私はまた、エラーのためにgoogled、しかし何か助けを見つけることができませんでした。

<?xml version="1.0" encoding="utf-8"?> 

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.mycompany.mobile.android.gui" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <instrumentation 
     android:name="android.test.InstrumentationTestRunner" 
     android:targetPackage="com.mycompany.mobile.android.gui" /> 
    <application> 
     <uses-library android:name="android.test.runner" /> 
    </application> 

    <uses-sdk android:targetSdkVersion="7" /> 
    <supports-screens android:anyDensity="true" /> 
    <uses-permission android:name="android.permission.INTERNET"></uses-permission> 
</manifest> 

そして、ここに私の計測テストがあります:

これは、テストプロジェクトのための私のAndroidManifest.xmlがどのように見えるかです。

パッケージcom.mycompany.mobile.android.gui;

import android.test.ActivityInstrumentationTestCase2; 

import com.mycompany.mobile.android.gui.AudioPlayerActivity; 

public class TestMusicPlayerActivityTest extends ActivityInstrumentationTestCase2<AudioPlayerActivity> { 
    public TestMusicPlayerActivityTest() { 
      super("com.mycompany.mobile.android.gui", AudioPlayerActivity.class); 
    } 

    public TestMusicPlayerActivityTest(String name) { 
     super("com.mycompany.mobile.android.gui", AudioPlayerActivity.class); 
    } 

    public TestMusicPlayerActivityTest(String pkg, Class<AudioPlayerActivity> activityClass) { 
     super("com.mycompany.mobile.android.gui", AudioPlayerActivity.class); 
    } 

    public void testSomething() { 
     System.out.println("Nothing works :("); 
     System.out.println(getActivity()); 
    } 
} 

私たちはすべてのプロセスをmavenで実行していますが、それは問題の一部ではありません。

ご覧のとおり、テスト済みのアクティビティも同じパッケージに含まれています。私はこの問題を抱えているほとんどの人々が行うように、パッケージ名の代わりにアクティビティのスーパーコンストラクタを呼び出すことはありません。ご関心を

、これはテストアクティビティ記述のAndroidManifest.xmlです:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.mycompany.mobile.android.gui" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <!-- omitted Uses permission + Uses SDK --> 
    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:debuggable="true" 
     android:theme="@style/NoTitleBar" 
    > 
    <!-- omitted other activities --> 
     <activity 
      android:name="com.mycompany.mobile.android.gui.AudioPlayerActivity" 
      android:screenOrientation="portrait" ></activity> 
    </application> 
</manifest> 

を私はまたのAndroidManifest.xmlに活動を追加しましたが、これは何も変更しませんでした。また、MAIN/LAUNCHERインテントフィルタを目的のアクティビティに追加しようとしましたが、テストの結果は変更されませんでした。私はエクストラを使って活動を始めようとしましたが、それがなければ結果も変わりませんでした。あなたは、Androidプロジェクトとして、それを実行している

答えて

4
<?xml version="1.0" encoding="utf-8"?> 

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.mycompany.mobile.android.gui" 
... ... 

AndroidプロジェクトとAndroidテストプロジェクトに同じパッケージ名を使用していますか?これは問題になる可能性がありますが、java.lang.RuntimeExceptionが発生するかどうかはわかりません。公式のdevのガイドhereによると、あなたのテストプロジェクトがあなたから別のパッケージ名を持っている必要があります

は、プロジェクトをテストした:

An Android package name is a unique system name for a .apk file, set by the "android:package" attribute of the element in the package's manifest. The Android package name of your test package must be different from the Android package name of the application under test. By default, Android tools create the test package name by appending ".test" to the package name of the application under test.

は、あなたのパッケージ名のcom.mycompany.mobile.android.gui.testを使用してみてくださいテストプロジェクト。

+0

これは現在無効です。 –

0

、< Javaパッケージをパッケージ-e Androidのテストプロジェクト

adbのシェル午前楽器として、それを実行してみてください>> /android.test.InstrumentationTestRunner

<テストAPKパッケージ-w
+0

私は悲しいので、私はそれをmavenで実行しています。私はpom.xml [ここ](http://pastie.org/private/a91ur2skgambknh2cryhba)をペーストしました。 testSourceDirectoryおよびsourceDirectoryフォルダを削除しても、結果は変更されませんでした。 – wonderb0lt

関連する問題