Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Robolectric如何测试DateFormat.getBestDateTimePattern()_Java_Android_Kotlin_Robolectric - Fatal编程技术网

Java Robolectric如何测试DateFormat.getBestDateTimePattern()

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

我使用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日,星期五


你应该在摘录中分享这两个结果。您期望的输出和来自
Robolectric
框架的输出。@PatrickW UpdateDrobelectric作为一个测试框架,期望您的输入应该与您选择的语言环境一致。您是否确保您的输入与预期的语言环境一致?您应该在摘录中共享这两个结果。您期望的输出和来自
Robolectric
框架的输出。@PatrickW UpdateDrobelectric作为一个测试框架,期望您的输入应该与您选择的语言环境一致。您是否确保您的输入与预期的语言环境一致?