不能得到的Andr​​oid ServiceTestCase运行 [英] Can not get Android ServiceTestCase to run

查看:107
本文介绍了不能得到的Andr​​oid ServiceTestCase运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法得到任何测试的情况下,扩展ServiceTestCase运行。没有,他们只是没有执行的错误。

I am unable to get any test cases that extend ServiceTestCase to run. There are no errors they are just not executed.

其他的测试用例,扩展AndroidTestCase做运行。

Other test cases that extend AndroidTestCase do run.

该项目设置如下:

我有一个Android的库包含的服务。它的清单文件如下:

I have a Android Library that contains a service. It's manifest file is as follows:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.something.android"
  android:versionCode="1"
  android:versionName="1.0">
<uses-sdk android:minSdkVersion="9"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application>
    <service android:name=".ExampleService" 
        android:exported="false"
    android:process=":example_service">
    </service>
</application>
</manifest>

Android的图书​​馆项目包含在文件夹中测试一个测试项目(使用Android工具创建的)

The Android Library Project contains a test project in the folder test (created using the Android tools)

这包含了AndroidManfiest.xml为如下:

This contains a AndroidManfiest.xml as as follows

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.something.android.tests"
      android:versionCode="1"
      android:versionName="1.0">
<application>
    <uses-library android:name="android.test.runner" />
</application>
<instrumentation android:name="android.test.InstrumentationTestRunner"
                 android:targetPackage="com.something.android.tests"
                 android:label="Tests for com.something.android"/>
</manifest>

我也有一个build.properties的测试项目,其中包含:

I also have a build.properties in the test project which contains:

tested.project.dir = .. android.library.reference.1 = ..

tested.project.dir=.. android.library.reference.1=..

我通过运行ant干净运行测试执行测试。

I execute the tests by running ant clean run-tests.

什么我需要做的就是将ServiceTestCase测试运行?

What do I need to do to get the ServiceTestCase test to run?

在此先感谢。

推荐答案

请确保您提供一个默认的构造函数ServiceTestCase。一个Eclipse的生成你可能并不合适。例如,在我的情况下产生的Eclipse我:

Make sure that you provide a default constructor for the ServiceTestCase. The one Eclipse generates for you may not be appropriate. For example, in my case Eclipse generated for me:

public class MyServiceTestCase extends ServiceTestCase<MyService> {

  public MyServiceTestCase(Class<MyService> serviceClass) {
    super(serviceClass);
  }
  ...
}

Android的JUnit的不能够实例MyServiceTestCase,但它并没有抱怨,我只能看到没有测试的情况下运行。

Android JUnit was not able to instantiate MyServiceTestCase, but it did not complain, and I only could see that no test cases where run.

Thefore我替换为以下构造,和它的工作很好:

Thefore I replaced the constructor with the following, and it worked nicely:

public class MyServiceTestCase extends ServiceTestCase<MyService> {

  public MyServiceTestCase() {
    super(MyService.class);
  }
  ...
}

希望它能为你工作。

Hope it works for you.

这篇关于不能得到的Andr​​oid ServiceTestCase运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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