清单的 Robolectric @Config 路径值 [英] Robolectric @Config path value for manifest

查看:63
本文介绍了清单的 Robolectric @Config 路径值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行 robolectric 单元测试,但我收到错误,因为在路径上找不到 AndroidManifest.xml.谁能给我一个@Config 清单值的示例路径.是相对路径还是绝对路径?

I am trying to run robolectric unit test but I am getting error as AndroidManifest.xml not found on path. Can anyone give me an example path of @Config manifest value. Is it relative path or absolute one?

提前致谢

推荐答案

如果你使用 maven 来运行你的测试,你可以设置如下:

If you are using maven to run your tests you can set as follows:

@Config(manifest = "../app/AndroidManifest.xml")
@RunWith(RobolectricTestRunner.class)
public class SomeTestCase { ... }

请注意,如果您使用的是 Android Studio/Intellij 并希望在 IDE 中运行您的测试,则必须在运行配置中进行更改.

在 Run->Edit configuration->Defaults->JUnit->Working directory 中设置值 $MODULE_DIR$,Android Studio 会像 Maven 一样设置所有 junit 的相对路径.

Please note that if you are using Android Studio/Intellij and want to run your tests within the IDE you will have to make a change in the Run configuration.

In Run->Edit configuration->Defaults->JUnit->Working directory set the value $MODULE_DIR$ and Android Studio will set the relative path in all junits just like Maven.

这对我有用,但是如果注释失败,您还可以创建一个名为org.robolectric.Config.properties"的文件并将其放在您的类路径中.
该文件应包含如下内容:清单:./app/AndroidManifest.xml"

This worked for me however if the annotation fails, you can also create a file called "org.robolectric.Config.properties" and place it on your classpath.
The file should contain something like the following: "manifest: ./app/AndroidManifest.xml"

可在此处找到更多信息:配置 Robolectric 2.0
可以在此处找到使用 maven 的简单配置:Simple Robolectric

More information can be found here: Configuring Robolectric 2.0
A simple configuration using maven can be found here: Simple Robolectric

这篇关于清单的 Robolectric @Config 路径值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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