I'm trying to using backticks ` in the definition of my instrumented tests. I don't understand why compiler complains about a strange error:
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
My test is a pretty standard instrumented test for 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)
}
}
If I remove backticks and spaces test compiles without any problem :(
That syntax is super-cool but it's not currently supported by Android runtime https://kotlinlang.org/docs/coding-conventions.html#names-for-test-methods
I think in the doc is missing the note about it's available in the unit tests on Android (that works on the JVM) and not in the instrumented tests (Android runtime)