无法解析的活动:意向时,仪器仪表,测试机器人活动 [英] Unable to resolve activity for: Intent when instrumentation-testing android activities

查看:188
本文介绍了无法解析的活动:意向时,仪器仪表,测试机器人活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误,当我试图在Android上运行insturmentation测试。我写了一个活动,叫做 AudioPlayerActivity 是出在封装的 com.mycompany.mobile.android.gui 的,现在我想要测试的GUI的项目,我在下面的错误正在运行的:

  

了java.lang.RuntimeException:无法解析活动:意向{行动= android.intent.action.MAIN FLG = 0x10000000处CMP = com.mycompany.mobile.android.gui / .AudioPlayerActivity}

我已经阅读这个问题和随后的意见存在,但无济于事。我也用Google搜索的错误,但没有发现任何帮助。

这是我的Andr​​oidManifest.xml中的测试项目如下:

< XML版本=1.0编码=UTF-8&GT?; <舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android     包=com.mycompany.mobile.android.gui     安卓版code =1     机器人:VERSIONNAME =1.0>     <仪器仪表         机器人:名称=android.test.InstrumentationTestRunner         机器人:targetPackage =com.mycompany.mobile.android.gui/>     <应用>         <使用库机器人:名称=android.test.runner/>     < /用途>     <使用-SDK机器人:targetSdkVersion =7/>     <支持屏安卓anyDensity =真/>     <使用-权限的Andr​​oid:名称=android.permission.INTERNET对>< /使用-许可> < /舱单>

这是我的仪表测试。

包com.mycompany.mobile.android.gui;

 进口android.test.ActivityInstrumentationTestCase2;

进口com.mycompany.mobile.android.gui.AudioPlayerActivity;

公共类TestMusicPlayerActivityTest扩展ActivityInstrumentationTestCase2< AudioPlayerActivity> {
    公共TestMusicPlayerActivityTest(){
            超(com.mycompany.mobile.android.gui,AudioPlayerActivity.class);
    }

    公共TestMusicPlayerActivityTest(字符串名称){
        超(com.mycompany.mobile.android.gui,AudioPlayerActivity.class);
    }

    公共TestMusicPlayerActivityTest(字符串PKG,类< AudioPlayerActivity> activityClass){
        超(com.mycompany.mobile.android.gui,AudioPlayerActivity.class);
    }

    公共无效testSomething(){
        的System.out.println(没有什么工作:();
        的System.out.println(getActivity());
    }
}
 

我们正在运行通过行家的整个过程,但是这不应该成为问题的一部分。

在测试活动,你可以看到,还在于在同一个包。我不叫超构造与活动的,而不是包名,因为有这个问题,大多数人做的。

为了您的利益,这是描述测试活动的Andr​​oidManifest.xml:

 < XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    包=com.mycompany.mobile.android.gui
    安卓版code =1
    机器人:VERSIONNAME =1.0>

    <! - 省略使用许可+使用SDK  - >
    <应用
        机器人:图标=@可绘制/ ic_launcher
        机器人:标签=@字符串/ APP_NAME
        机器人:可调试=真
        机器人:主题=@风格/ NoTitleBar
    >
    <! - 忽略其他活动 - >
        <活动
            机器人:名称=com.mycompany.mobile.android.gui.AudioPlayerActivity
            机器人:screenOrientation =画像和GT;< /活性GT;
    < /用途>
< /舱单>
 

我还增加了活动的Andr​​oidManifest.xml中,但这并没有改变任何东西。我还尝试添加在MAIN / LAUNCHER意图过滤器所需的活性,但这种不改变测试的结果。我曾尝试先从群众演员,并没有他们的活动,也没有改变的结果。

解决方案

 < XML版本=1.0编码=UTF-8&GT?;

<舱单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  包=com.mycompany.mobile.android.gui
......
 

您使用为您的Andr​​oid项目和Android测试项目相同的包叫什么名字?这可能是一个问题,但我不知道这是否会导致你的java.lang.RuntimeException的。

据官方开发指南 ,您的测试项目必须具有不同的包的名字从你测试项目:

  

这是Android包名称是一个的apk文件一个唯一的系统名称,通过设置安卓包的包清单元素的属性。 您的测试包的Andr​​oid包名称必须测试的应用程序的Andr​​oid包名称不同。默认情况下,Android的工具创建测试包名通过附加.TEST来的包名测试的应用程序。

请尝试使用包名com.mycompany.mobile.android.gui.test为您的测试项目。

I'm getting errors when I'm trying to run insturmentation tests on android. I've written an Activity, called AudioPlayerActivity that lies in the package com.mycompany.mobile.android.gui, and now I'm trying to test the GUI of that project and I'm running in the following error:

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

I have read this question, and followed the advice there, but to no avail. I also googled for the error, but did not find any help.

This is how my AndroidManifest.xml for the test project looks like:

<?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>

And here's my Instrumentation test.

package 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());
    }   
}

We are running the entire process via maven, but that should not be a part of the problem.

The tested Activity, as you can see, also lies in the same package. I don't call the super constructor with the activity's instead of the package name, as most people having this issue do.

For your interest, this is the AndroidManifest.xml describing the tested activity:

<?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>

I also added the activity to the AndroidManifest.xml, but this didn't change anything. I also tried adding the MAIN/LAUNCHER intent filter for the desired activity, but to this didn't change the outcome of the test. I have tried starting the activity with extras and without them, that also didn't change the outcome.

解决方案

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

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

Are you using the same package name for both your Android project and Android test project? This could be a problem, though I am not sure if it causes your java.lang.RuntimeException.

According to the official dev guide here, Your test project must have a different package name from you tested project:

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.

Try using package name com.mycompany.mobile.android.gui.test for your test project.

这篇关于无法解析的活动:意向时,仪器仪表,测试机器人活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆