defer() 我正在研究 RxKotlin,出现了一个问题:和 之间有什么区别defer{}
我已在->模块中导入mockk库。测试类中没有导入错误,但是当我运行测试时,我收到如下错误:commonTestshared
Unresolved reference: every
Unresolved reference: mockk
Unresolved reference: verify
Run Code Online (Sandbox Code Playgroud)
在我使用mock库方法的所有地方。错误的原因可能是什么?
我的测试示例在控制台中出现错误:
class DefaultAppPreferenceStorageTest {
val appPreference = mockk<AppPreference>() //Unresolved reference: mockk
val jsonService = mockk<JsonService>() //Unresolved reference: mockk
val jsonKey = "key"
val value = 1
val stringValue = "$value"
val defaultIntValue = Random.nextInt()
val storage = DefaultAppPreferenceStorage(
appPreference,
jsonService
)
inner class PutJsonTest {
@BeforeTest
fun beforeEachTest() {
every { jsonService.mapToString(value) } returns stringValue //Unresolved reference: every
storage.putJson(jsonKey, value)
}
@Test
fun …Run Code Online (Sandbox Code Playgroud) 我需要在 TextView 中显示百分比值,例如“15 %”,我通过这种方式在 viewModel 中执行此操作,并且它有效:
perfusionIndexValue.postValue(
list.lastOrNull()?.perfusionIndex?.takeIf {
it != PerfusionIndex.NO_DATA
}?.value?.toString().orEmpty() + " %"
)
Run Code Online (Sandbox Code Playgroud)
但如果我用资源来做:
perfusionIndexValue.postValue(
list.lastOrNull()?.perfusionIndex?.takeIf {
it != PerfusionIndex.NO_DATA
}?.value?.toString().orEmpty() + Resources.getSystem().getString(R.string.pi_percent)
)
Run Code Online (Sandbox Code Playgroud)
我明白了
io.reactivex.rxjava3.exceptions.UndeliverableException: The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with. Further reading: https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#error-handling | android.content.res.Resources$NotFoundException: String resource ID #0x7f0e0081
Run Code Online (Sandbox Code Playgroud)
我如何设置像“15%”这样的文本