Android Studio 2.3 更新导致 Robolectric 单元测试失败 [英] Robolectric Unit Test failing with Android Studio 2.3 updates

查看:39
本文介绍了Android Studio 2.3 更新导致 Robolectric 单元测试失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所有的单元测试都开始抛出这个错误:

All my Unit Test started throwing this error:

No such manifest file: build\intermediates\bundles\debug\AndroidManifest.xml

java.lang.NullPointerException
    at org.robolectric.shadows.ShadowAssetManager.getAndResolve(ShadowAssetManager.java:375)
    at org.robolectric.shadows.ShadowAssetManager.getResourceValue(ShadowAssetManager.java:117)
    at android.content.res.AssetManager.getResourceValue(AssetManager.java)
    at android.content.res.Resources.getValue(Resources.java:1347)
    at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:332)
    at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:197)
    at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:190)
    at android.support.v7.widget.AppCompatDrawableManager.checkVectorDrawableSetup(AppCompatDrawableManager.java:711)
    at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:195)
    at android.support.v7.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:81)
    at android.support.v7.app.AppCompatDelegateImplBase.__constructor__(AppCompatDelegateImplBase.java:131)
    at android.support.v7.app.AppCompatDelegateImplBase.<init>(AppCompatDelegateImplBase.java)
    at android.support.v7.app.AppCompatDelegateImplV9.<init>(AppCompatDelegateImplV9.java)
    at android.support.v7.app.AppCompatDelegateImplV11.<init>(AppCompatDelegateImplV11.java)
    at android.support.v7.app.AppCompatDelegateImplV14.<init>(AppCompatDelegateImplV14.java)
    at android.support.v7.app.AppCompatDelegateImplV23.<init>(AppCompatDelegateImplV23.java)
    at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:203)
    at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:185)
    at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:519)
    at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
    at android.app.Activity.performCreate(Activity.java:6237)
    at org.robolectric.util.ReflectionHelpers.callInstanceMethod(ReflectionHelpers.java:195)
    at org.robolectric.util.ActivityController$1.run(ActivityController.java:126)
    at org.robolectric.shadows.ShadowLooper.runPaused(ShadowLooper.java:340)
    at org.robolectric.shadows.CoreShadowsAdapter$2.runPaused(CoreShadowsAdapter.java:40)
    at org.robolectric.util.ActivityController.create(ActivityController.java:123)
    at org.robolectric.util.ActivityController.create(ActivityController.java:133)
    at com.si.play.adapter.RosterAdapter2Test.setUp(RosterAdapter2Test.java:43)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
    at org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:250)
    at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:176)
    at org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:142)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)

它工作得很好.我唯一改变的是我将 Android Studio 更新到 2.3,将 gradle 插件更新到 2.3.到目前为止,我通过在每个测试的运行配置路径中手动写下 $MODULE_DIR$ 来修复它.但是每次都写下来真的很烦.有没有人遇到过这样的情况?

It worked just fine. The only thing that I changed is that I updated Android Studio to 2.3 and the gradle plugin to 2.3. So far I fix it by manually writing down $MODULE_DIR$ in each test's Run Configuration path. But is really annoying write it down every time. Has anyone experience something like this?

推荐答案

默认设置,这样你创建的每一个新的测试配置都会继承它:

Set it by default, so every new test configuration that you create will inherit it:

运行 > 编辑配置... > 默认 > Android JUnit

工作目录中输入:$MODULE_DIR$

这篇关于Android Studio 2.3 更新导致 Robolectric 单元测试失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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