简体   繁体   English

RobolectricTestRunner在多模块Maven项目中找不到清单文件

[英]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.

相关问题 在多模块android studio项目中集成.aar文件 - Integrate .aar file in multi-module android studio project 在多模块项目中集成 Crashlytics - Integrating Crashlytics in a multi-module project Maven-与JavaME,JavaSE和Android模块共享多模块项目的记录器 - Maven - share a logger for multi-module project with JavaME, JavaSE and Android modules Android多模块项目因TypeNotPresentException失败 - Android multi-module project fails with TypeNotPresentException 在多模块项目中使用 Firebase - Using Firebase in a multi-module project Android Studio仅为多模块项目中不依赖模块的模块生成R文件 - Android Studio generates R file only for modules with no module dependencies in multi-module project Gradle api与多模块项目实施的最佳实践 - Best practice for Gradle api vs implementation in multi-module project 将多模块Android Intellij Project移植到Android Studio - porting multi-module Android Intellij Project to Android Studio 在多模块项目上运行Proguard作为“单件” - Run Proguard on multi-module project as “one piece” Jetpack Compose 无法在多模块项目中编译 - Jetpack Compose does not compile in a multi-module project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM