Robolectric 2.3 - 测试支持。片段失败"您需要使用Theme.AppCompat主题"

时间:2014-08-11 23:16:58

标签: android robolectric

我正在为support.Fragment编写测试,但我一直得到以下异常:

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

当我尝试启动片段时(在活动创建期间)抛出异常:

@RunWith(RobolectricTestRunner.class)
public class AuthFragmentTest extends TestCase {   

    private SupportFragment fragment;

    @Before
    public void setUp() throws Exception {
        fragment = new SupportFragment();

        FragmentTestUtil.startFragment(fragment, SupportFragmentActivity.class);
    }
}

这是我正在使用的API级别。

<uses-sdk
    android:minSdkVersion="10"
    android:targetSdkVersion="19" />

此外,Robolectric配置为使用与/src/test/resources/org.robolectric.Config.properties

相同的Manifest作为应用程序。

我的应用程序运行没有问题,支持库正确设置,这只是我似乎无法正确的测试。

1 个答案:

答案 0 :(得分:1)

对于遇到此问题的人,可以找到潜在的解决方案-here

您提供的主题必须是Theme.MaterialComponents的子元素