小编Sun*_*y13的帖子

defer() 和 defer{} 有什么区别

defer() 我正在研究 RxKotlin,出现了一个问题:和 之间有什么区别defer{}

kotlin rx-java rx-kotlin

3
推荐指数
1
解决办法
319
查看次数

未解决的参考:mock

我已在->模块中导入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)

junit kotlin-multiplatform mockk

2
推荐指数
1
解决办法
4058
查看次数

获取viewmodel中的字符串资源

我需要在 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%”这样的文本

android viewmodel kotlin rx-java

1
推荐指数
1
解决办法
5247
查看次数