Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ServiceTestCase未启动我的服务_Android_Unit Testing_Testing_Junit_Servicetestcase - Fatal编程技术网

Android ServiceTestCase未启动我的服务

Android ServiceTestCase未启动我的服务,android,unit-testing,testing,junit,servicetestcase,Android,Unit Testing,Testing,Junit,Servicetestcase,我正在尝试为我的android应用程序编写一些JUnit测试。应用程序是一种服务 我尝试了几种方法让ServiceTestCase启动服务,但失败了 但是,当我调试ServiceTestCase时,它将启动服务。我相信这是因为ServiceTestCase正在调用安装程序,并且没有给服务足够的时间在它终止之前启动 我不完全确定,这是我第一次在android上使用junit测试。这是很新的。有什么建议可以解决这个问题吗 我在考虑创建一些计时器循环之类的东西,但那看起来真的很脏。我想要一个更干净的套

我正在尝试为我的android应用程序编写一些JUnit测试。应用程序是一种服务

我尝试了几种方法让ServiceTestCase启动服务,但失败了

但是,当我调试ServiceTestCase时,它将启动服务。我相信这是因为ServiceTestCase正在调用安装程序,并且没有给服务足够的时间在它终止之前启动

我不完全确定,这是我第一次在android上使用junit测试。这是很新的。有什么建议可以解决这个问题吗

我在考虑创建一些计时器循环之类的东西,但那看起来真的很脏。我想要一个更干净的套间


服务的Android清单。
我错误地引用了一个依赖项目。一旦解决了这个问题,它就解决了这个问题。因此,如果您遇到相同的问题,请检查并确保您正确引用了您的项目

Android Manifest for the service.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="dataservice.server"
    <uses-sdk android:minSdkVersion="10" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <service android:name="dataservice.server.DataServer"  android:process=":remote" android:exported="true" android:enabled="true">
            <intent-filter>
                <action android:name="dataservice.DataService.BIND.1" />
            </intent-filter>
            <intent-filter>
                <action android:name= ".DataServer" />
            </intent-filter>
        </service>
        <receiver android:name="dataservice.server.Receiver">
            <intent-filter>
                <action android:name="android.intent.action.USER_PRESENT"></action>
                <action android:name="android.intent.action.BOOT_COMPLETED"></action>
            </intent-filter>
        </receiver>
    </application>
</manifest>
The ServiceTestCase i am attempting.
public class Publish extends ServiceTestCase<DataServer> {

    private final static String TAG = "Publish Unit Test";
    private Context mSystemContext;

    public Publish() {
        super(DataServer.class);
    }

    public Publish(Class<DataServer> serviceClass) {
        super(serviceClass);
    }

    @Override
    protected void setUp() throws Exception {
        // TODO Auto-generated method stub
        super.setUp();
                // this is where i am attempting to start the service.
                // i have attempted other methods, but none of those worked either.
                startService(new Intent(this.getContext(), DataServer.class));
    }

    public void testPublish() {
      }
}