launchFragment while testing showing error

Viewed 337

Using this guide to test dialog https://developer.android.com/guide/fragments/test The bottom sample

with(launchFragment<MyDialogFragment>()) {
        onFragment { fragment -> // here error
            assertThat(fragment.dialog).isNotNull()
            assertThat(fragment.requireDialog().isShowing).isTrue()
            fragment.dismiss()
            fragment.parentFragmentManager.executePendingTransactions()
            assertThat(fragment.dialog).isNull()
        }
    }

But here it shows error

 onFragment { fragment -> // error below

Type mismatch. Required: FragmentScenario.FragmentAction Found: (???) → Unit Cannot infer a type for this parameter. Please specify it explicitly

2 Answers

Guys the solution was Kotlin version. So update Kotlin plugin in studio solves the issue

The solution is to change the kotlin version in module build.gradle.

buildscript {
    ext {
        ...
        kotlin_version = "1.5.31"
    }
}

My origin kotlin version is 1.3.x, and it happened with the same error.

Then I go to github for the guide and found out that.

Related