Android Unit Test启动模拟器但不启动测试

时间:2012-04-23 20:03:37

标签: android junit

我试图创建一个扩展AndroidTestCase的单元测试来测试BroadcastReceiver。 在测试中我是:

  • 实例化接收器
  • 使用所需的操作和额外参数创建意图
  • 使用intent和getContext()
  • 调用接收器

当我点击调试为Android JUnit测试时,它启动模拟器(启动良好且可用)启动,然后它以27%挂起尝试启动实际测试并且它永远不会发生。

我做错了什么?

编辑,代码段

    public class RemoteControlReceiverTest extends AndroidTestCase {
    public RemoteControlReceiverTest() {
        super();
    }

    private RemoteControlReceiver mReceiver;
    private String accountSettings;

    @Override
    protected void setUp() throws Exception
    {
        super.setUp();

        mReceiver = new RemoteControlReceiver();
        accountSettings = "<y>gmail</y><u></u><n>test</n><t>smtp+ssl+://::@:25</t><s>imap+ssl+://:test@:143</s>";
    }

    public void testStartActivity()
    {   
        Intent addIntent = new Intent();
        addIntent.setAction("com.kaseya.email.K9RemoteControl.addAccount");
        addIntent.putExtra("accountSettings", accountSettings);

        mReceiver.onReceive(getContext(), addIntent);
    }
}

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

        <uses-sdk android:minSdkVersion="3" />

        <instrumentation
            android:name="android.test.InstrumentationTestRunner"
            android:targetPackage="com.kaseya.email" />

        <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name" >
            <uses-library android:name="android.test.runner" />
        </application>

    </manifest>

0 个答案:

没有答案
相关问题