Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot spy lambda since Kotlin 2.0 #524

Open
ganadist opened this issue Aug 23, 2024 · 2 comments
Open

Cannot spy lambda since Kotlin 2.0 #524

ganadist opened this issue Aug 23, 2024 · 2 comments

Comments

@ganadist
Copy link

  • Reproducible step
$ git clone https://github.com/ganadist/minimal-reproducible-example -b k2-spy-lambda k2
Cloning into 'k2'...

$ cd k2
$ git checkout HEAD~1

# perform unittest with kotlin 1.9.23
$ ./gradlew :app:tDDUT
...
MainActivityTest > test1 STARTED

OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended

MainActivityTest > test1 PASSED


$ git checkout origin/k2-spy-lambda

# perform unittest with kotlin 2.0.20
$ ./gradlew :app:tDDUT

MainActivityTest > test1 STARTED

OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended

MainActivityTest > test1 FAILED
    org.mockito.exceptions.base.MockitoException at MainActivityTest.kt:31

Test code : https://github.com/ganadist/minimal-reproducible-example/blob/k2-spy-lambda/app/src/test/java/com/example/myapplication/MainActivityTest.kt#L31

Stacktrace on Gradle Scan

@ganadist
Copy link
Author

My quick fix is

@@ -28,7 +28,7 @@ class MainActivityTest {
         LayoutInflater.from(ApplicationProvider.getApplicationContext())
     )

-    private val inflateView: () -> ActivityMainBinding = spy(value = { binding })
+    private val inflateView: () -> ActivityMainBinding = spy(value = ::binding )

     @Before
     fun setUp() {

@ganadist
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant