kotlin com.android.tools.r8.internal.Jc:DEX版本040之前的版本不允许在SimpleName异常中使用空格字符

zbsbpyhn  于 2023-03-13  发布在  Kotlin
关注(0)|答案(1)|浏览(186)

我试图在我的插桩测试定义中使用反勾号。我不明白为什么编译器会抱怨一个奇怪的错误:

Caused by: com.android.tools.r8.internal.Jj: com.android.tools.r8.internal.Jc: Space characters in SimpleName 'given a closebottomsheetevent eventlistener onCloseBottomSheet should be called' are not allowed prior to DEX version 040

我的测试是compose的一个相当标准的仪器化测试

package com.dooitu.mobile.android.ui.homefeed

import android.content.Context
import androidx.activity.ComponentActivity
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import com.dooitu.mobile.android.ui.homefeed.components.HomeFeedEvent
import com.dooitu.mobile.android.ui.homefeed.models.HomeFeedScreenEventListener
import com.dooitu.mobile.android.ui.theme.DooituTheme
import org.junit.Rule
import org.junit.Test
import org.koin.androidx.compose.get

class HomeFeedScreenTest {
    @get:Rule
    // Use a dummy activity instead of real MainActivity
    val composeTestRule = createAndroidComposeRule<ComponentActivity>()
    private var triggeredEventId: Int? = null
    private val eventListener = object : HomeFeedScreenEventListener {
        override fun onCloseBottomSheet() {
            triggeredEventId = ON_CLOSE_BOTTOM_SHEET_EVENT_ID
        }

        override fun onOpenComments(postId: String, numberOfComments: Int) {
            triggeredEventId = ON_OPEN_COMMENTS_EVENT_ID
        }

        override fun onOpenShare(shareLink: String, context: Context) {
            TODO("Not yet implemented")
        }

        override fun onOpenPostSingleView(postId: String) {
            TODO("Not yet implemented")
        }

        override fun onOpenPostActions(postId: String, userId: String) {
            TODO("Not yet implemented")
        }

        override fun onOpenPostDetails(postId: String) {
            TODO("Not yet implemented")
        }

        override fun onProfileImageClicked(userId: String, isCurrentUser: Boolean) {
            TODO("Not yet implemented")
        }
    }
    private val updateViewModel = HomeFeedUpdateViewModel()

    private fun startScenario(state: State<HomeFeedState>) {
        composeTestRule.setContent {
            DooituTheme.SurfaceContainer {
                HomeFeedScreen(
                    state = state,
                    viewModel = get(),
                    cacheDataSourceFactory = get(),
                    getReloadedPostFlow = updateViewModel::reloadedPost,
                    eventsListener = eventListener,
                    logScreenView = {}
                )
            }
        }
    }

    @Test
    fun `given a closebottomsheetevent eventlistener on close bottom sheet should be called` () {
        val closeBottomSheetState = mutableStateOf(
            HomeFeedState(
                emptyList(),
                emptyList(),
                event = HomeFeedEvent.CloseBottomSheet
            )
        )
        // Start the app
        startScenario(closeBottomSheetState)
        assert(triggeredEventId == ON_CLOSE_BOTTOM_SHEET_EVENT_ID)
    }
}

如果我删除反引号和空格,测试编译没有任何问题:(

bhmjp9jg

bhmjp9jg1#

这种语法非常酷,但目前Android运行时不支持https://kotlinlang.org/docs/coding-conventions.html#names-for-test-methods
我认为文档中缺少关于它在Android上的单元测试(在JVM上工作)中可用而在 Jmeter 化测试(Android运行时)中不可用的说明

相关问题