我具有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 SimpleDateFormat(pattern, Locale(locale)).format(date)
但是Robolectric似乎有问题,因为DateFormat类和DateFormat.getBestDateTimePattern()的阴影没有产生错误的结果。
有什么想法可以使用DateFormat.getBestDateTimePattern()为方法编写单元测试,而又不为整个类编写阴影吗?
更新:
在真实设备上看起来不错,但是在单元测试中却不是
3月3日,星期五
结果是:
3月3日,星期五