android – 带有Theme.AppCompat的Robolectric 3.3

前端之家收集整理的这篇文章主要介绍了android – 带有Theme.AppCompat的Robolectric 3.3前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在使用Robolectric 3.3从com.android.support:appcompat-v7:23.4.0测试AppCompatActivity
我得到之后:

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

我创建了以下测试运行器:

public class ActivityTestRunner extends RobolectricTestRunner {

    public ActivityTestRunner(Class

然后我得到:

java.lang.NullPointerException
    at org.robolectric.res.ThemeStyleSet$OverlayedStyle.equals(ThemeStyleSet.java:67)
    at org.robolectric.res.ThemeStyleSet.apply(ThemeStyleSet.java:29)
    at org.robolectric.shadows.ShadowAssetManager.applyThemeStyle(ShadowAssetManager.java:595)
    at org.robolectric.shadows.ShadowAssetManager.applyThemeStyle(ShadowAssetManager.java:588)
    at android.content.res.AssetManager.applyThemeStyle(AssetManager.java)
    at android.content.res.Resources$Theme.applyStyle(Resources.java:1104)
    at android.view.ContextThemeWrapper.onApplyThemeResource(ContextThemeWrapper.java:132)
    at android.app.Activity.onApplyThemeResource(Activity.java:3307)
    at android.view.ContextThemeWrapper.initializeTheme(ContextThemeWrapper.java:144)
    at android.view.ContextThemeWrapper.setTheme(ContextThemeWrapper.java:89)
    at android.support.v7.app.AppCompatActivity.setTheme(AppCompatActivity.java:90)
    at org.robolectric.shadows.ShadowActivity.setThemeFromManifest(ShadowActivity.java:89)
    at org.robolectric.shadows.CoreShadowsAdapter$1.setThemeFromManifest(CoreShadowsAdapter.java:30)
    at org.robolectric.android.controller.ActivityController.attach(ActivityController.java:84)
    at org.robolectric.android.controller.ActivityController.of(ActivityController.java:34)
    at org.robolectric.Robolectric.buildActivity(Robolectric.java:93)
    at org.robolectric.Robolectric.buildActivity(Robolectric.java:89)
    at org.robolectric.Robolectric.setupActivity(Robolectric.java:97)
    at com.lacoon.components.activities.MainActivityTest.setUp(MainActivityTest.java:35)
    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.internal.SandBoxTestRunner$2.evaluate(SandBoxTestRunner.java:209)
    at org.robolectric.internal.SandBoxTestRunner.runChild(SandBoxTestRunner.java:109)
    at org.robolectric.internal.SandBoxTestRunner.runChild(SandBoxTestRunner.java:36)
    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.internal.SandBoxTestRunner$1.evaluate(SandBoxTestRunner.java:63)
    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)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

样式: