我知道这个话题已经讨论过了,但这里有点不同:
- 应用程序运行良好
- 错误仅在单元测试中显示
- 主题很好(新创建的示例项目)
如何重现:
- 创建一个新项目 --> FullScreenActivity Android 4.3
- 创建单元测试
运行
public class FullscreenActivityTest extends ActivityUnitTestCase<FullscreenActivity> { public FullscreenActivityTest() { super(FullscreenActivity.class); } public void testStart() { startActivity(new Intent(getInstrumentation() .getTargetContext(), FullscreenActivity.class), null, null); Assert.assertNotNull(getActivity()); }
}
经测试:
- Nexus 5 模拟器
- Nexus 6P 模拟器
每次相同,应用程序都可以正常工作。单元测试失败:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:124)
at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
at com.sample.foobar.FullscreenActivity.onCreate(FullscreenActivity.java:88)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.test.ActivityUnitTestCase.startActivity(ActivityUnitTestCase.java:163)
谢谢,
保罗