微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Robolectric环境中的android.text.format.Time类初始化

如何解决Robolectric环境中的android.text.format.Time类初始化

Robolectric (单元测试)环境中初始化android.text.format.Time类(Time time = new Time())的实例时遇到异常。如何配置此单元测试环境以绕过此问题?

这是我用于单元测试的配置-

@RunWith(RobolectricTestRunner.class)
@Config(sdk = 28)
@PowerMockIgnore({"org.mockito.*","android.*","org.json.*})

这是我得到的例外-

java.lang.ExceptionInInitializerError
    at android.text.format.Time$TimeCalculator.lookupZoneInfo(Time.java:1110)
    at android.text.format.Time$TimeCalculator.__constructor__(Time.java:1070)
    at android.text.format.Time$TimeCalculator.<init>(Time.java)
    at android.text.format.Time.initialize(Time.java:208)
    at android.text.format.Time.__constructor__(Time.java:184)
    at android.text.format.Time.<init>(Time.java)
    ........
        ........
   
 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.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.powermock.modules.junit4.rule.PowerMockStatement$1.run(PowerMockRule.java:83)
    at org.powermock.reflect.internal.WhiteBoxImpl.performMethodInvocation(WhiteBoxImpl.java:1854)
    at org.powermock.reflect.internal.WhiteBoxImpl.doInvokeMethod(WhiteBoxImpl.java:816)
    at org.powermock.reflect.internal.WhiteBoxImpl.invokeMethod(WhiteBoxImpl.java:681)
    at org.powermock.reflect.WhiteBox.invokeMethod(WhiteBox.java:401)
    at org.powermock.classloading.AbstractClassloaderExecutor.getResult(AbstractClassloaderExecutor.java:76)
    at org.powermock.classloading.AbstractClassloaderExecutor.invokeWithClassLoader(AbstractClassloaderExecutor.java:64)
    at org.powermock.classloading.AbstractClassloaderExecutor.executeWithClassLoader(AbstractClassloaderExecutor.java:56)
    at org.powermock.classloading.SingleClassloaderExecutor.execute(SingleClassloaderExecutor.java:33)
    at org.powermock.classloading.AbstractClassloaderExecutor.execute(AbstractClassloaderExecutor.java:40)
    at org.powermock.modules.junit4.rule.PowerMockStatement.evaluate(PowerMockRule.java:75)
    at org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:546)
    at org.robolectric.internal.SandBoxTestRunner$2.lambda$evaluate$0(SandBoxTestRunner.java:252)
    at org.robolectric.internal.bytecode.SandBox.lambda$runOnMainThread$0(SandBox.java:89)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。