[英]RobolectricTestRunner cannot find manifest file in multi-module maven project
Let's start with my setup. 让我们从我的设置开始。 I have a multi-module maven project:
我有一个多模块的Maven项目:
ProjectRoot
\moduleA
\moduleB
(relevant) content of moduleA: 模块A的(相关)内容:
- AndroidManifest.xml
- src\main\java\HelloWorldActivity
- src\test\java\HelloWorldActivityTest
HelloWorldActivityTest is annotated with: @RunWith(RoboelectricTestRunner.class) HelloWorldActivityTest带有以下注释:@RunWith(RoboelectricTestRunner.class)
My problem is that if I specify the manifest location it will either not work in IntelliJ IDEA or Maven (from command prompt). 我的问题是,如果我指定清单位置,则该位置将无法在IntelliJ IDEA或Maven中运行(从命令提示符)。
If I specify the location to be: "/moduleA/AndroidManifest.xml" it works in IntelliJ If I specify the location to be "/AndroidManifest.xml" it works in Maven 如果我将位置指定为:“ /moduleA/AndroidManifest.xml”,则可以在IntelliJ中使用。如果我将位置指定为“ /AndroidManifest.xml”,则可以在Maven中使用。
So the specified path will be interpreted as relative to the project root (in the case of Maven) or the project module (in the case of IntelliJ) 因此,指定的路径将被解释为相对于项目根目录(对于Maven)或相对于项目模块(对于IntelliJ)
To make it work in both cases I use an ugly workaround right now by setting a property when the project is built with maven and if the property is not set I do: 为了使其在两种情况下均能正常工作,我现在使用一个丑陋的解决方法,方法是在使用maven构建项目时设置属性,如果未设置该属性,我会这样做:
System.setProperty("android.manifest", "moduleA/AndroidManifest.xml");
System.setProperty("android.resources", "moduleA/res");
System.setProperty("android.assets", "moduleA/assets");
Please tell me there is a better way. 请告诉我有更好的方法。 And no, I will not change the project structure to have a separate test module (unless you give me a very good reason)!
不,我不会将项目结构更改为具有单独的测试模块(除非您给我一个很好的理由)!
Set up your tests to work with Maven. 设置测试以与Maven一起使用。 Then in Intellij go to Edit Configurations-->Defaults-->Junit and change your "Working Directory" to $MODULE_DIR$ .
然后在Intellij中转到编辑配置->默认值-> Junit并将“工作目录”更改为$ MODULE_DIR $ 。 You'll probably have to delete your previous test run configurations for this to take effect.
您可能必须删除以前的测试运行配置才能生效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.