Java Robolectric如何测试DateFormat.getBestDateTimePattern()
我使用Robolectric进行了测试单元测试:Java Robolectric如何测试DateFormat.getBestDateTimePattern(),java,android,kotlin,robolectric,Java,Android,Kotlin,Robolectric,我使用Robolectric进行了测试单元测试: @Test @Config(qualifiers = "en") 在测试方法中,类似这样: val locale = context.resources.getString(R.string.language_locale) val pattern = android.text.format.DateFormat.getBestDateTimePattern(Locale(locale), "EEE, d MMM") return Simp
@Test
@Config(qualifiers = "en")
在测试方法中,类似这样:
val locale = context.resources.getString(R.string.language_locale)
val pattern = android.text.format.DateFormat.getBestDateTimePattern(Locale(locale), "EEE, d MMM")
return SimpleDateFormat(pattern, Locale(locale)).format(date)
但看起来Robolectric在这方面有问题,因为DateFormat类和DateFormat.getBestDateTimePattern()都没有阴影,导致了错误的结果
知道如何使用DateFormat.getBestDateTimePattern()为方法编写单元测试而不为整个类编写阴影吗?
更新:
在真正的设备上,它看起来不错,但在单元测试上,而不是
3月3日,星期五
结果是:
3月3日,星期五
你应该在摘录中分享这两个结果。您期望的输出和来自
Robolectric
框架的输出。@PatrickW UpdateDrobelectric作为一个测试框架,期望您的输入应该与您选择的语言环境一致。您是否确保您的输入与预期的语言环境一致?您应该在摘录中共享这两个结果。您期望的输出和来自Robolectric
框架的输出。@PatrickW UpdateDrobelectric作为一个测试框架,期望您的输入应该与您选择的语言环境一致。您是否确保您的输入与预期的语言环境一致?