无法让 Android ServiceTestCase 运行
我无法获得任何扩展 ServiceTestCase 来运行的测试用例。没有错误,只是没有执行。
扩展 AndroidTestCase 的其他测试用例确实可以运行。
项目设置如下:
我有一个包含服务的 Android 库。它的清单文件如下:
<?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 库项目在 test 文件夹中包含一个测试项目(使用 Android 工具创建)
这包含一个 AndroidManfiest.xml 如下
<?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,其中包含
: .project.dir=.. android.library.reference.1=..
我通过运行 ant clean run-tests 来执行测试。
我需要做什么才能运行 ServiceTestCase 测试?
提前致谢。
I am unable to get any test cases that extend ServiceTestCase to run. There are no errors they are just not executed.
Other test cases that extend AndroidTestCase do run.
The projects are set up as follows:
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>
The Android Library Project contains a test project in the folder test (created using the Android tools)
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>
I also have a build.properties in the test project which contains:
tested.project.dir=..
android.library.reference.1=..
I execute the tests by running ant clean run-tests.
What do I need to do to get the ServiceTestCase test to run?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保为 ServiceTestCase 提供默认构造函数。 Eclipse 为您生成的那个可能不合适。例如,在我的例子中,Eclipse 为我生成了:
Android JUnit 无法实例化 MyServiceTestCase,但它没有抱怨,我只能看到没有测试用例运行。
因此,我用以下内容替换了构造函数,并且效果很好:
希望它对您有用。
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:
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 I replaced the constructor with the following, and it worked nicely:
Hope it works for you.
接受的答案不再对我有用。
ATSL 链接
他们似乎忘记更新实际文档。
The accepted answer doesn't work for me any more.
ATSL link
It seems they forgot to update the actual documentation.