1

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

  • 实例化接收器
  • 使用所需的操作和额外参数创建意图
  • 使用意图和 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>
4

0 回答 0