AndroidStudio之Robolectric单元测试 No Such manifest file

来源:互联网 发布:手机话费购物软件 编辑:程序博客网 时间:2024/06/05 21:50

最近在学习AndroidStudio之单元测试 Robolectric 推荐系列文章最详细没有之一:关于安卓单元测试,你需要知道的一切

在学习到使用dagger2来做依赖注入,以及在单元测试中的应用这篇文章使用Dagger2 对Activity做测试时出现了

No such manifest file: build/intermediates/bundles/debug/AndroidManifest.xml 这个奇怪的问题

之前测试纯java代码时完全没有问题 使用@Config(mainfest="xxx/AndroidManifest.xml")指定清单文件的路径也是不行

各种百度、谷歌姿势都试了但没有太好的答案 在Robolectric官方集成说明文档 有这么一段话 但是针对Mac和Linux的没有Windows 

If you are on Linux or on a Mac, you will probably need to configure the default JUnit test runner configuration in order to work around a bug where Android Studio does not set the working directory to the module being tested. This can be accomplished by editing the run configurations, Defaults -> JUnit and changing the working directory value to $MODULE_DIR$.

后来还是在Robolectric的GitHub上找到了答案:https://github.com/robolectric/robolectric/issues/2949

只要测试Activity相关需要实例化Activity对象的都需要在Configurations中配置问题working directory就完美解决了不只是在Mac、Linux上Windows同样需要此配置

^_^ 官方文档也应该更新了呢


配置之后再运行时发现需要下载android7.1.0的相关配置的东西 之后就可以完美运行了

我的配置:

       Robolectric 3.4-rc2
     Android Studio version 2.3.2
     Gradle version 3.3
     Android Gradle plugin 2.3.2

compileSdkVersion25

  buildToolsVersion "25.0.3"
  targetSdkVersion 25

最后我彦神镇楼----





阅读全文
0 0
原创粉丝点击