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

coVerify verifies wrong method #1247

Open
3 tasks done
MurashkoIlya opened this issue May 6, 2024 · 0 comments
Open
3 tasks done

coVerify verifies wrong method #1247

MurashkoIlya opened this issue May 6, 2024 · 0 comments

Comments

@MurashkoIlya
Copy link

MurashkoIlya commented May 6, 2024

Prerequisites

  • I am running the latest version
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed

Expected Behavior

Expected that coVerify would verify right method that is inside braces

Current Behavior

Currently coVerify is failing because it verifies Dispatchers.getDefault() method

Steps to Reproduce

  1. Create simple suspend function test with coVerify
  2. mock Dispatchers.Default

Context

I need to mock every dispatcher in Dispatchers object. But some tests with coVerify are failing with

  • MockK version: 1.13.10
  • OS: Mac OS Sonoma 14.4.1
  • Kotlin version: 1.9.23
  • JDK version:
  • JUnit version: 4.13.2
  • Type of test: unit

Failure Logs

Please include any relevant log snippets or files here.

Stack trace

// -----------------------[ YOUR STACK STARTS HERE ] -----------------------
java.lang.AssertionError: Verification failed: call 1 of 2: class kotlinx.coroutines.Dispatchers.getDefault()). 3 matching calls found, but needs at least 1 and at most 1 calls
Calls:
1) class kotlinx.coroutines.Dispatchers.getMain()
2) class kotlinx.coroutines.Dispatchers.getMain()
3) class kotlinx.coroutines.Dispatchers.getDefault()
4) class kotlinx.coroutines.Dispatchers.getDefault()
5) class kotlinx.coroutines.Dispatchers.getDefault()


Stack traces:
1)                                                 io.mockk.impl.InternalPlatform.captureStackTrace            (InternalPlatform.kt:130)                    
                                                     io.mockk.impl.stub.MockKStub.handleInvocation             (MockKStub.kt:253)                           
                   io.mockk.impl.instantiation.JvmMockFactoryHelper$mockHandler$1.invocation                   (JvmMockFactoryHelper.kt:24)                 
                                            io.mockk.proxy.jvm.advice.Interceptor.call                         (Interceptor.kt:21)                          
                                                   kotlinx.coroutines.Dispatchers.getMain                      (Dispatchers.kt:20)                          
                         kotlinx.coroutines.test.internal.TestMainDispatcherJvmKt.getTestMainDispatcher        (TestMainDispatcherJvm.kt:24)                
                                          kotlinx.coroutines.test.TestDispatchers.setMain                      (TestDispatchers.kt:21)                      
                                               com.example.Test.setUp                        (Test.kt:35)                                 
                                    jdk.internal.reflect.NativeMethodAccessorImpl.invoke0                      (-:-2)N                                      
                                    jdk.internal.reflect.NativeMethodAccessorImpl.invoke                       (-:-1)                                       
                                jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke                       (-:-1)                                       
                                                         java.lang.reflect.Method.invoke                       (-:-1)                                       
                                        org.junit.runners.model.FrameworkMethod$1.runReflectiveCall            (FrameworkMethod.java:59)                    
                              org.junit.internal.runners.model.ReflectiveCallable.run                          (ReflectiveCallable.java:12)                 
                                          org.junit.runners.model.FrameworkMethod.invokeExplosively            (FrameworkMethod.java:56)                    
                                 org.junit.internal.runners.statements.RunBefores.invokeMethod                 (RunBefores.java:33)                         
                                 org.junit.internal.runners.statements.RunBefores.evaluate                     (RunBefores.java:24)                         
                                  org.junit.internal.runners.statements.RunAfters.evaluate                     (RunAfters.java:27)                          
                                                 org.junit.runners.ParentRunner$3.evaluate                     (ParentRunner.java:306)                      
                                       org.junit.runners.BlockJUnit4ClassRunner$1.evaluate                     (BlockJUnit4ClassRunner.java:100)            
                                                   org.junit.runners.ParentRunner.runLeaf                      (ParentRunner.java:366)                      
                                         org.junit.runners.BlockJUnit4ClassRunner.runChild                     (BlockJUnit4ClassRunner.java:103)            
                                         org.junit.runners.BlockJUnit4ClassRunner.runChild                     (BlockJUnit4ClassRunner.java:63)             
                                                 org.junit.runners.ParentRunner$4.run                          (ParentRunner.java:331)                      
                                                 org.junit.runners.ParentRunner$1.schedule                     (ParentRunner.java:79)                       
                                                   org.junit.runners.ParentRunner.runChildren                  (ParentRunner.java:329)                      
                                                   org.junit.runners.ParentRunner.access$100                   (ParentRunner.java:66)                       
                                                 org.junit.runners.ParentRunner$2.evaluate                     (ParentRunner.java:293)                      
                                                 org.junit.runners.ParentRunner$3.evaluate                     (ParentRunner.java:306)                      
                                                   org.junit.runners.ParentRunner.run                          (ParentRunner.java:413)                      
               org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass                 (JUnitTestClassExecutor.java:112)            
               org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute                      (JUnitTestClassExecutor.java:58)             
               org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute                      (JUnitTestClassExecutor.java:40)             
      org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass             (AbstractJUnitTestClassProcessor.java:60)    
                    org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass             (SuiteTestClassProcessor.java:52)            
                                    jdk.internal.reflect.NativeMethodAccessorImpl.invoke0                      (-:-2)N                                      
                                    jdk.internal.reflect.NativeMethodAccessorImpl.invoke                       (-:-1)                                       
                                jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke                       (-:-1)                                       
                                                         java.lang.reflect.Method.invoke                       (-:-1)                                       
                                  org.gradle.internal.dispatch.ReflectionDispatch.dispatch                     (ReflectionDispatch.java:36)                 
                                  org.gradle.internal.dispatch.ReflectionDispatch.dispatch                     (ReflectionDispatch.java:24)                 
                          org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch                     (ContextClassLoaderDispatch.java:33)         
   org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke                       (ProxyDispatchAdapter.java:94)               
                                                               jdk.proxy2.$Proxy5.processTestClass             (-:-1)                                       
                        org.gradle.api.internal.tasks.testing.worker.TestWorker$2.run                          (TestWorker.java:176)                        
                          org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName (TestWorker.java:129)                        
                          org.gradle.api.internal.tasks.testing.worker.TestWorker.execute                      (TestWorker.java:100)                        
                          org.gradle.api.internal.tasks.testing.worker.TestWorker.execute                      (TestWorker.java:60)                         
                   org.gradle.process.internal.worker.child.ActionExecutionWorker.execute                      (ActionExecutionWorker.java:56)              
      org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call                         (SystemApplicationClassLoaderWorker.java:113)
      org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call                         (SystemApplicationClassLoaderWorker.java:65) 
                       worker.org.gradle.process.internal.worker.GradleWorkerMain.run                          (GradleWorkerMain.java:69)                   
                       worker.org.gradle.process.internal.worker.GradleWorkerMain.main                         (GradleWorkerMain.java:74)                   

2)                                                 io.mockk.impl.InternalPlatform.captureStackTrace                                (InternalPlatform.kt:130)                    
                                                     io.mockk.impl.stub.MockKStub.handleInvocation                                 (MockKStub.kt:253)                           
                   io.mockk.impl.instantiation.JvmMockFactoryHelper$mockHandler$1.invocation                                       (JvmMockFactoryHelper.kt:24)                 
                                            io.mockk.proxy.jvm.advice.Interceptor.call                                             (Interceptor.kt:21)                          
                                                   kotlinx.coroutines.Dispatchers.getMain                                          (Dispatchers.kt:20)                          
                    kotlinx.coroutines.test.internal.TestMainDispatcher$Companion.getCurrentTestDispatcher$kotlinx_coroutines_test (TestMainDispatcher.kt:47)                   
                    kotlinx.coroutines.test.internal.TestMainDispatcher$Companion.getCurrentTestScheduler$kotlinx_coroutines_test  (TestMainDispatcher.kt:50)                   
                               kotlinx.coroutines.test.TestCoroutineDispatchersKt.StandardTestDispatcher                           (TestCoroutineDispatchers.kt:142)            
                               kotlinx.coroutines.test.TestCoroutineDispatchersKt.StandardTestDispatcher$default                   (TestCoroutineDispatchers.kt:138)            
                                              kotlinx.coroutines.test.TestScopeKt.withDelaySkipping                                (TestScope.kt:197)                           
                                              kotlinx.coroutines.test.TestScopeKt.TestScope                                        (TestScope.kt:164)                           
                           kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0                                  (TestBuilders.kt:168)                        
                                           kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0                                  (-:1)                                        
                           kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0$default                          (TestBuilders.kt:160)                        
                                           kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0$default                          (-:1)                                        
                                               com.example.Test.test                                             (Test.kt:40)                                 
                                    jdk.internal.reflect.NativeMethodAccessorImpl.invoke0                                          (-:-2)N                                      
                                    jdk.internal.reflect.NativeMethodAccessorImpl.invoke                                           (-:-1)                                       
                                jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke                                           (-:-1)                                       
                                                         java.lang.reflect.Method.invoke                                           (-:-1)                                       
                                        org.junit.runners.model.FrameworkMethod$1.runReflectiveCall                                (FrameworkMethod.java:59)                    
                              org.junit.internal.runners.model.ReflectiveCallable.run                                              (ReflectiveCallable.java:12)                 
                                          org.junit.runners.model.FrameworkMethod.invokeExplosively                                (FrameworkMethod.java:56)                    
                               org.junit.internal.runners.statements.InvokeMethod.evaluate                                         (InvokeMethod.java:17)                       
                                 org.junit.internal.runners.statements.RunBefores.evaluate                                         (RunBefores.java:26)                         
                                  org.junit.internal.runners.statements.RunAfters.evaluate                                         (RunAfters.java:27)                          
                                                 org.junit.runners.ParentRunner$3.evaluate                                         (ParentRunner.java:306)                      
                                       org.junit.runners.BlockJUnit4ClassRunner$1.evaluate                                         (BlockJUnit4ClassRunner.java:100)            
                                                   org.junit.runners.ParentRunner.runLeaf                                          (ParentRunner.java:366)                      
                                         org.junit.runners.BlockJUnit4ClassRunner.runChild                                         (BlockJUnit4ClassRunner.java:103)            
                                         org.junit.runners.BlockJUnit4ClassRunner.runChild                                         (BlockJUnit4ClassRunner.java:63)             
                                                 org.junit.runners.ParentRunner$4.run                                              (ParentRunner.java:331)                      
                                                 org.junit.runners.ParentRunner$1.schedule                                         (ParentRunner.java:79)                       
                                                   org.junit.runners.ParentRunner.runChildren                                      (ParentRunner.java:329)                      
                                                   org.junit.runners.ParentRunner.access$100                                       (ParentRunner.java:66)                       
                                                 org.junit.runners.ParentRunner$2.evaluate                                         (ParentRunner.java:293)                      
                                                 org.junit.runners.ParentRunner$3.evaluate                                         (ParentRunner.java:306)                      
                                                   org.junit.runners.ParentRunner.run                                              (ParentRunner.java:413)                      
               org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass                                     (JUnitTestClassExecutor.java:112)            
               org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute                                          (JUnitTestClassExecutor.java:58)             
               org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute                                          (JUnitTestClassExecutor.java:40)             
      org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass                                 (AbstractJUnitTestClassProcessor.java:60)    
                    org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass                                 (SuiteTestClassProcessor.java:52)            
                                    jdk.internal.reflect.NativeMethodAccessorImpl.invoke0                                          (-:-2)N                                      
                                    jdk.internal.reflect.NativeMethodAccessorImpl.invoke                                           (-:-1)                                       
                                jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke                                           (-:-1)                                       
                                                         java.lang.reflect.Method.invoke                                           (-:-1)                                       
                                  org.gradle.internal.dispatch.ReflectionDispatch.dispatch                                         (ReflectionDispatch.java:36)                 
                                  org.gradle.internal.dispatch.ReflectionDispatch.dispatch                                         (ReflectionDispatch.java:24)                 
                          org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch                                         (ContextClassLoaderDispatch.java:33)         
   org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke                                           (ProxyDispatchAdapter.java:94)               
                                                               jdk.proxy2.$Proxy5.processTestClass                                 (-:-1)                                       
                        org.gradle.api.internal.tasks.testing.worker.TestWorker$2.run                                              (TestWorker.java:176)                        
                          org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName                     (TestWorker.java:129)                        
                          org.gradle.api.internal.tasks.testing.worker.TestWorker.execute                                          (TestWorker.java:100)                        
                          org.gradle.api.internal.tasks.testing.worker.TestWorker.execute                                          (TestWorker.java:60)                         
                   org.gradle.process.internal.worker.child.ActionExecutionWorker.execute                                          (ActionExecutionWorker.java:56)              
      org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call                                             (SystemApplicationClassLoaderWorker.java:113)
      org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call                                             (SystemApplicationClassLoaderWorker.java:65) 
                       worker.org.gradle.process.internal.worker.GradleWorkerMain.run                                              (GradleWorkerMain.java:69)                   
                       worker.org.gradle.process.internal.worker.GradleWorkerMain.main                                             (GradleWorkerMain.java:74)                   

3)                                                 io.mockk.impl.InternalPlatform.captureStackTrace            (InternalPlatform.kt:130)                    
                                                     io.mockk.impl.stub.MockKStub.handleInvocation             (MockKStub.kt:253)                           
                   io.mockk.impl.instantiation.JvmMockFactoryHelper$mockHandler$1.invocation                   (JvmMockFactoryHelper.kt:24)                 
                                            io.mockk.proxy.jvm.advice.Interceptor.call                         (Interceptor.kt:21)                          
                                                   kotlinx.coroutines.Dispatchers.getDefault                   (Dispatchers.kt:17)                          
                                            kotlinx.coroutines.CoroutineContextKt.newCoroutineContext          (CoroutineContext.kt:17)                     
                                        kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking                  (Builders.kt:59)                             
                                                    kotlinx.coroutines.BuildersKt.runBlocking                  (-:1)                                        
                                        kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default          (Builders.kt:48)                             
                                                    kotlinx.coroutines.BuildersKt.runBlocking$default          (-:1)                                        
                                        kotlinx.coroutines.test.TestBuildersJvmKt.createTestResult             (TestBuildersJvm.kt:10)                      
                           kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0              (TestBuilders.kt:310)                        
                                           kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0              (-:1)                                        
                           kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0              (TestBuilders.kt:168)                        
                                           kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0              (-:1)                                        
                           kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0$default      (TestBuilders.kt:160)                        
                                           kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0$default      (-:1)                                        
                                               com.example.Test.test                         (Test.kt:40)                                 
                                    jdk.internal.reflect.NativeMethodAccessorImpl.invoke0                      (-:-2)N                                      
                                    jdk.internal.reflect.NativeMethodAccessorImpl.invoke                       (-:-1)                                       
                                jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke                       (-:-1)                                       
                                                         java.lang.reflect.Method.invoke                       (-:-1)                                       
                                        org.junit.runners.model.FrameworkMethod$1.runReflectiveCall            (FrameworkMethod.java:59)                    
                              org.junit.internal.runners.model.ReflectiveCallable.run                          (ReflectiveCallable.java:12)                 
                                          org.junit.runners.model.FrameworkMethod.invokeExplosively            (FrameworkMethod.java:56)                    
                               org.junit.internal.runners.statements.InvokeMethod.evaluate                     (InvokeMethod.java:17)                       
                                 org.junit.internal.runners.statements.RunBefores.evaluate                     (RunBefores.java:26)                         
                                  org.junit.internal.runners.statements.RunAfters.evaluate                     (RunAfters.java:27)                          
                                                 org.junit.runners.ParentRunner$3.evaluate                     (ParentRunner.java:306)                      
                                       org.junit.runners.BlockJUnit4ClassRunner$1.evaluate                     (BlockJUnit4ClassRunner.java:100)            
                                                   org.junit.runners.ParentRunner.runLeaf                      (ParentRunner.java:366)                      
                                         org.junit.runners.BlockJUnit4ClassRunner.runChild                     (BlockJUnit4ClassRunner.java:103)            
                                         org.junit.runners.BlockJUnit4ClassRunner.runChild                     (BlockJUnit4ClassRunner.java:63)             
                                                 org.junit.runners.ParentRunner$4.run                          (ParentRunner.java:331)                      
                                                 org.junit.runners.ParentRunner$1.schedule                     (ParentRunner.java:79)                       
                                                   org.junit.runners.ParentRunner.runChildren                  (ParentRunner.java:329)                      
                                                   org.junit.runners.ParentRunner.access$100                   (ParentRunner.java:66)                       
                                                 org.junit.runners.ParentRunner$2.evaluate                     (ParentRunner.java:293)                      
                                                 org.junit.runners.ParentRunner$3.evaluate                     (ParentRunner.java:306)                      
                                                   org.junit.runners.ParentRunner.run                          (ParentRunner.java:413)                      
               org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass                 (JUnitTestClassExecutor.java:112)            
               org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute                      (JUnitTestClassExecutor.java:58)             
               org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute                      (JUnitTestClassExecutor.java:40)             
      org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass             (AbstractJUnitTestClassProcessor.java:60)    
                    org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass             (SuiteTestClassProcessor.java:52)            
                                    jdk.internal.reflect.NativeMethodAccessorImpl.invoke0                      (-:-2)N                                      
                                    jdk.internal.reflect.NativeMethodAccessorImpl.invoke                       (-:-1)                                       
                                jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke                       (-:-1)                                       
                                                         java.lang.reflect.Method.invoke                       (-:-1)                                       
                                  org.gradle.internal.dispatch.ReflectionDispatch.dispatch                     (ReflectionDispatch.java:36)                 
                                  org.gradle.internal.dispatch.ReflectionDispatch.dispatch                     (ReflectionDispatch.java:24)                 
                          org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch                     (ContextClassLoaderDispatch.java:33)         
   org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke                       (ProxyDispatchAdapter.java:94)               
                                                               jdk.proxy2.$Proxy5.processTestClass             (-:-1)                                       
                        org.gradle.api.internal.tasks.testing.worker.TestWorker$2.run                          (TestWorker.java:176)                        
                          org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName (TestWorker.java:129)                        
                          org.gradle.api.internal.tasks.testing.worker.TestWorker.execute                      (TestWorker.java:100)                        
                          org.gradle.api.internal.tasks.testing.worker.TestWorker.execute                      (TestWorker.java:60)                         
                   org.gradle.process.internal.worker.child.ActionExecutionWorker.execute                      (ActionExecutionWorker.java:56)              
      org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call                         (SystemApplicationClassLoaderWorker.java:113)
      org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call                         (SystemApplicationClassLoaderWorker.java:65) 
                       worker.org.gradle.process.internal.worker.GradleWorkerMain.run                          (GradleWorkerMain.java:69)                   
                       worker.org.gradle.process.internal.worker.GradleWorkerMain.main                         (GradleWorkerMain.java:74)                   

4)                                                 io.mockk.impl.InternalPlatform.captureStackTrace            (InternalPlatform.kt:130)                    
                                                     io.mockk.impl.stub.MockKStub.handleInvocation             (MockKStub.kt:253)                           
                   io.mockk.impl.instantiation.JvmMockFactoryHelper$mockHandler$1.invocation                   (JvmMockFactoryHelper.kt:24)                 
                                            io.mockk.proxy.jvm.advice.Interceptor.call                         (Interceptor.kt:21)                          
                                                   kotlinx.coroutines.Dispatchers.getDefault                   (Dispatchers.kt:17)                          
                                            kotlinx.coroutines.CoroutineContextKt.newCoroutineContext          (CoroutineContext.kt:17)                     
                                 kotlinx.coroutines.BuildersKt__Builders_commonKt.launch                       (Builders.common.kt:48)                      
                                                    kotlinx.coroutines.BuildersKt.launch                       (-:1)                                        
                                 kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default               (Builders.common.kt:43)                      
                                                    kotlinx.coroutines.BuildersKt.launch$default               (-:1)                                        
               kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt$runTest$2$1.invokeSuspend                (TestBuilders.kt:320)                        
               kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt$runTest$2$1.invoke                       (TestBuilders.kt:-1)                         
               kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt$runTest$2$1.invoke                       (TestBuilders.kt:-1)                         
                     kotlinx.coroutines.test.TestBuildersJvmKt$createTestResult$1.invokeSuspend                (TestBuildersJvm.kt:11)                      
                              kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith                   (ContinuationImpl.kt:33)                     
                                                kotlinx.coroutines.DispatchedTask.run                          (DispatchedTask.kt:104)                      
                                             kotlinx.coroutines.EventLoopImplBase.processNextEvent             (EventLoop.common.kt:277)                    
                                             kotlinx.coroutines.BlockingCoroutine.joinBlocking                 (Builders.kt:95)                             
                                        kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking                  (Builders.kt:69)                             
                                                    kotlinx.coroutines.BuildersKt.runBlocking                  (-:1)                                        
                                        kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default          (Builders.kt:48)                             
                                                    kotlinx.coroutines.BuildersKt.runBlocking$default          (-:1)                                        
                                        kotlinx.coroutines.test.TestBuildersJvmKt.createTestResult             (TestBuildersJvm.kt:10)                      
                           kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0              (TestBuilders.kt:310)                        
                                           kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0              (-:1)                                        
                           kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0              (TestBuilders.kt:168)                        
                                           kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0              (-:1)                                        
                           kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0$default      (TestBuilders.kt:160)                        
                                           kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0$default      (-:1)                                        
                                               com.example.Test.test                         (Test.kt:40)                                 
                                    jdk.internal.reflect.NativeMethodAccessorImpl.invoke0                      (-:-2)N                                      
                                    jdk.internal.reflect.NativeMethodAccessorImpl.invoke                       (-:-1)                                       
                                jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke                       (-:-1)                                       
                                                         java.lang.reflect.Method.invoke                       (-:-1)                                       
                                        org.junit.runners.model.FrameworkMethod$1.runReflectiveCall            (FrameworkMethod.java:59)                    
                              org.junit.internal.runners.model.ReflectiveCallable.run                          (ReflectiveCallable.java:12)                 
                                          org.junit.runners.model.FrameworkMethod.invokeExplosively            (FrameworkMethod.java:56)                    
                               org.junit.internal.runners.statements.InvokeMethod.evaluate                     (InvokeMethod.java:17)                       
                                 org.junit.internal.runners.statements.RunBefores.evaluate                     (RunBefores.java:26)                         
                                  org.junit.internal.runners.statements.RunAfters.evaluate                     (RunAfters.java:27)                          
                                                 org.junit.runners.ParentRunner$3.evaluate                     (ParentRunner.java:306)                      
                                       org.junit.runners.BlockJUnit4ClassRunner$1.evaluate                     (BlockJUnit4ClassRunner.java:100)            
                                                   org.junit.runners.ParentRunner.runLeaf                      (ParentRunner.java:366)                      
                                         org.junit.runners.BlockJUnit4ClassRunner.runChild                     (BlockJUnit4ClassRunner.java:103)            
                                         org.junit.runners.BlockJUnit4ClassRunner.runChild                     (BlockJUnit4ClassRunner.java:63)             
                                                 org.junit.runners.ParentRunner$4.run                          (ParentRunner.java:331)                      
                                                 org.junit.runners.ParentRunner$1.schedule                     (ParentRunner.java:79)                       
                                                   org.junit.runners.ParentRunner.runChildren                  (ParentRunner.java:329)                      
                                                   org.junit.runners.ParentRunner.access$100                   (ParentRunner.java:66)                       
                                                 org.junit.runners.ParentRunner$2.evaluate                     (ParentRunner.java:293)                      
                                                 org.junit.runners.ParentRunner$3.evaluate                     (ParentRunner.java:306)                      
                                                   org.junit.runners.ParentRunner.run                          (ParentRunner.java:413)                      
               org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass                 (JUnitTestClassExecutor.java:112)            
               org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute                      (JUnitTestClassExecutor.java:58)             
               org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute                      (JUnitTestClassExecutor.java:40)             
      org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass             (AbstractJUnitTestClassProcessor.java:60)    
                    org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass             (SuiteTestClassProcessor.java:52)            
                                    jdk.internal.reflect.NativeMethodAccessorImpl.invoke0                      (-:-2)N                                      
                                    jdk.internal.reflect.NativeMethodAccessorImpl.invoke                       (-:-1)                                       
                                jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke                       (-:-1)                                       
                                                         java.lang.reflect.Method.invoke                       (-:-1)                                       
                                  org.gradle.internal.dispatch.ReflectionDispatch.dispatch                     (ReflectionDispatch.java:36)                 
                                  org.gradle.internal.dispatch.ReflectionDispatch.dispatch                     (ReflectionDispatch.java:24)                 
                          org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch                     (ContextClassLoaderDispatch.java:33)         
   org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke                       (ProxyDispatchAdapter.java:94)               
                                                               jdk.proxy2.$Proxy5.processTestClass             (-:-1)                                       
                        org.gradle.api.internal.tasks.testing.worker.TestWorker$2.run                          (TestWorker.java:176)                        
                          org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName (TestWorker.java:129)                        
                          org.gradle.api.internal.tasks.testing.worker.TestWorker.execute                      (TestWorker.java:100)                        
                          org.gradle.api.internal.tasks.testing.worker.TestWorker.execute                      (TestWorker.java:60)                         
                   org.gradle.process.internal.worker.child.ActionExecutionWorker.execute                      (ActionExecutionWorker.java:56)              
      org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call                         (SystemApplicationClassLoaderWorker.java:113)
      org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call                         (SystemApplicationClassLoaderWorker.java:65) 
                       worker.org.gradle.process.internal.worker.GradleWorkerMain.run                          (GradleWorkerMain.java:69)                   
                       worker.org.gradle.process.internal.worker.GradleWorkerMain.main                         (GradleWorkerMain.java:74)                   

5)                                                  io.mockk.impl.InternalPlatform.captureStackTrace                            (InternalPlatform.kt:130)                    
                                                      io.mockk.impl.stub.MockKStub.handleInvocation                             (MockKStub.kt:253)                           
                    io.mockk.impl.instantiation.JvmMockFactoryHelper$mockHandler$1.invocation                                   (JvmMockFactoryHelper.kt:24)                 
                                             io.mockk.proxy.jvm.advice.Interceptor.call                                         (Interceptor.kt:21)                          
                                                    kotlinx.coroutines.Dispatchers.getDefault                                   (Dispatchers.kt:17)                          
                                             kotlinx.coroutines.CoroutineContextKt.newCoroutineContext                          (CoroutineContext.kt:17)                     
                                         kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking                                  (Builders.kt:59)                             
                                                     kotlinx.coroutines.BuildersKt.runBlocking                                  (-:1)                                        
                                         kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default                          (Builders.kt:48)                             
                                                     kotlinx.coroutines.BuildersKt.runBlocking$default                          (-:1)                                        
                                                      io.mockk.InternalPlatformDsl.runCoroutine                                 (InternalPlatformDsl.kt:22)                  
                                         io.mockk.impl.eval.RecordedBlockEvaluator.initializeCoroutines                         (RecordedBlockEvaluator.kt:86)               
                                           io.mockk.impl.eval.VerifyBlockEvaluator.verify                                       (VerifyBlockEvaluator.kt:21)                 
                                                                 io.mockk.MockKDsl.internalCoVerify                             (API.kt:145)                                 
                                                                  io.mockk.MockKKt.coVerify                                     (MockK.kt:244)                               
                                                                  io.mockk.MockKKt.coVerify$default                             (MockK.kt:235)                               
                                         com.example.Test$test$1.invokeSuspend                                (Test.kt:42)                                 
                                         com.example.Test$test$1.invoke                                       (Test.kt:-1)                                 
                                         com.example.Test$test$1.invoke                                       (Test.kt:-1)                                 
              kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt$runTest$2$1$1.invokeSuspend                                (TestBuilders.kt:316)                        
                               kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith                                   (ContinuationImpl.kt:33)                     
                                                 kotlinx.coroutines.DispatchedTask.run                                          (DispatchedTask.kt:104)                      
                                            kotlinx.coroutines.test.TestDispatcher.processEvent$kotlinx_coroutines_test         (TestDispatcher.kt:24)                       
                                    kotlinx.coroutines.test.TestCoroutineScheduler.tryRunNextTaskUnless$kotlinx_coroutines_test (TestCoroutineScheduler.kt:99)               
   kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt$runTest$2$1$workRunner$1.invokeSuspend                                (TestBuilders.kt:322)                        
                               kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith                                   (ContinuationImpl.kt:33)                     
                                                 kotlinx.coroutines.DispatchedTask.run                                          (DispatchedTask.kt:104)                      
                                              kotlinx.coroutines.EventLoopImplBase.processNextEvent                             (EventLoop.common.kt:277)                    
                                              kotlinx.coroutines.BlockingCoroutine.joinBlocking                                 (Builders.kt:95)                             
                                         kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking                                  (Builders.kt:69)                             
                                                     kotlinx.coroutines.BuildersKt.runBlocking                                  (-:1)                                        
                                         kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default                          (Builders.kt:48)                             
                                                     kotlinx.coroutines.BuildersKt.runBlocking$default                          (-:1)                                        
                                         kotlinx.coroutines.test.TestBuildersJvmKt.createTestResult                             (TestBuildersJvm.kt:10)                      
                            kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0                              (TestBuilders.kt:310)                        
                                            kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0                              (-:1)                                        
                            kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0                              (TestBuilders.kt:168)                        
                                            kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0                              (-:1)                                        
                            kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt.runTest-8Mi8wO0$default                      (TestBuilders.kt:160)                        
                                            kotlinx.coroutines.test.TestBuildersKt.runTest-8Mi8wO0$default                      (-:1)                                        
                                                com.example.Test.test                                         (Test.kt:40)                                 
                                     jdk.internal.reflect.NativeMethodAccessorImpl.invoke0                                      (-:-2)N                                      
                                     jdk.internal.reflect.NativeMethodAccessorImpl.invoke                                       (-:-1)                                       
                                 jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke                                       (-:-1)                                       
                                                          java.lang.reflect.Method.invoke                                       (-:-1)                                       
                                         org.junit.runners.model.FrameworkMethod$1.runReflectiveCall                            (FrameworkMethod.java:59)                    
                               org.junit.internal.runners.model.ReflectiveCallable.run                                          (ReflectiveCallable.java:12)                 
                                           org.junit.runners.model.FrameworkMethod.invokeExplosively                            (FrameworkMethod.java:56)                    
                                org.junit.internal.runners.statements.InvokeMethod.evaluate                                     (InvokeMethod.java:17)                       
                                  org.junit.internal.runners.statements.RunBefores.evaluate                                     (RunBefores.java:26)                         
                                   org.junit.internal.runners.statements.RunAfters.evaluate                                     (RunAfters.java:27)                          
                                                  org.junit.runners.ParentRunner$3.evaluate                                     (ParentRunner.java:306)                      
                                        org.junit.runners.BlockJUnit4ClassRunner$1.evaluate                                     (BlockJUnit4ClassRunner.java:100)            
                                                    org.junit.runners.ParentRunner.runLeaf                                      (ParentRunner.java:366)                      
                                          org.junit.runners.BlockJUnit4ClassRunner.runChild                                     (BlockJUnit4ClassRunner.java:103)            
                                          org.junit.runners.BlockJUnit4ClassRunner.runChild                                     (BlockJUnit4ClassRunner.java:63)             
                                                  org.junit.runners.ParentRunner$4.run                                          (ParentRunner.java:331)                      
                                                  org.junit.runners.ParentRunner$1.schedule                                     (ParentRunner.java:79)                       
                                                    org.junit.runners.ParentRunner.runChildren                                  (ParentRunner.java:329)                      
                                                    org.junit.runners.ParentRunner.access$100                                   (ParentRunner.java:66)                       
                                                  org.junit.runners.ParentRunner$2.evaluate                                     (ParentRunner.java:293)                      
                                                  org.junit.runners.ParentRunner$3.evaluate                                     (ParentRunner.java:306)                      
                                                    org.junit.runners.ParentRunner.run                                          (ParentRunner.java:413)                      
                org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass                                 (JUnitTestClassExecutor.java:112)            
                org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute                                      (JUnitTestClassExecutor.java:58)             
                org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute                                      (JUnitTestClassExecutor.java:40)             
       org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass                             (AbstractJUnitTestClassProcessor.java:60)    
                     org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass                             (SuiteTestClassProcessor.java:52)            
                                     jdk.internal.reflect.NativeMethodAccessorImpl.invoke0                                      (-:-2)N                                      
                                     jdk.internal.reflect.NativeMethodAccessorImpl.invoke                                       (-:-1)                                       
                                 jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke                                       (-:-1)                                       
                                                          java.lang.reflect.Method.invoke                                       (-:-1)                                       
                                   org.gradle.internal.dispatch.ReflectionDispatch.dispatch                                     (ReflectionDispatch.java:36)                 
                                   org.gradle.internal.dispatch.ReflectionDispatch.dispatch                                     (ReflectionDispatch.java:24)                 
                           org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch                                     (ContextClassLoaderDispatch.java:33)         
    org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke                                       (ProxyDispatchAdapter.java:94)               
                                                                jdk.proxy2.$Proxy5.processTestClass                             (-:-1)                                       
                         org.gradle.api.internal.tasks.testing.worker.TestWorker$2.run                                          (TestWorker.java:176)                        
                           org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName                 (TestWorker.java:129)                        
                           org.gradle.api.internal.tasks.testing.worker.TestWorker.execute                                      (TestWorker.java:100)                        
                           org.gradle.api.internal.tasks.testing.worker.TestWorker.execute                                      (TestWorker.java:60)                         
                    org.gradle.process.internal.worker.child.ActionExecutionWorker.execute                                      (ActionExecutionWorker.java:56)              
       org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call                                         (SystemApplicationClassLoaderWorker.java:113)
       org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call                                         (SystemApplicationClassLoaderWorker.java:65) 
                        worker.org.gradle.process.internal.worker.GradleWorkerMain.run                                          (GradleWorkerMain.java:69)                   
                        worker.org.gradle.process.internal.worker.GradleWorkerMain.main                                         (GradleWorkerMain.java:74)                   
// -----------------------[ YOUR STACK TRACE ENDS HERE ] -----------------------

Minimal reproducible code (the gist of this issue)

// -----------------------[ GRADLE DEFINITIONS ] -----------------------

module-commonunittest-impl = [
    # test
    "junit",
    "mockk",
    "coroutines-test",
    "turbine",
    "robolectric",
    "mockito-core",
    "kotlin-test-junit",
    "kotlin-test",
    # common
    "dagger-core",
    "gson",
]
api(libs.bundles.module.commonunittest.impl)

// -----------------------[ YOUR CODE STARTS HERE ] -----------------------
import io.mockk.coVerify
import io.mockk.every
import io.mockk.mockkStatic
import io.mockk.spyk
import io.mockk.unmockkStatic
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.TestCoroutineScheduler
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.test.setMain
import org.junit.After
import org.junit.Before
import org.junit.Test

class TestTest {
    suspend fun foo() {

    }
}

class Test {

    private val testScheduler = TestCoroutineScheduler()
    private val testDispatcher get() = StandardTestDispatcher(testScheduler)

    private val testClass = spyk(TestTest())

    @OptIn(ExperimentalCoroutinesApi::class)
    @Before
    fun setUp() {
        mockkStatic(Dispatchers::class)
        Dispatchers.setMain(testDispatcher)
        every { Dispatchers.Default } returns testDispatcher
    }

    @Test
    fun test() = runTest {
        testClass.foo()
        coVerify(exactly = 1) { testClass.foo() }
    }

    @After
    fun clear() {
        unmockkStatic(Dispatchers::class)
    }
}
// -----------------------[ YOUR CODE ENDS HERE ] -----------------------
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