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

io.mockk.MockKException: can't find stub Disposable(temporary mock) #786 #800

Open
periva101 opened this issue Mar 14, 2022 · 1 comment
Labels

Comments

@periva101
Copy link

Expected Behavior
test pass

Current Behavior
io.mockk.MockKException: can't find stub Disposable(temporary mock)

Failure Information (for bugs)
io.mockk.MockKException: can't find stub Disposable(temporary mock)
at app//io.mockk.impl.stub.StubRepository.stubFor(StubRepository.kt:16)
at app//io.mockk.impl.recording.states.AnsweringState.call(AnsweringState.kt:13)
at app//io.mockk.impl.recording.CommonCallRecorder.call(CommonCallRecorder.kt:53)
at app//io.mockk.impl.stub.MockKStub.handleInvocation(MockKStub.kt:266)
at app//io.mockk.impl.instantiation.JvmMockFactoryHelper$mockHandler$1.invocation(JvmMockFactoryHelper.kt:23)
at app//io.mockk.proxy.jvm.advice.Interceptor.call(Interceptor.kt:21)
at app//io.mockk.proxy.jvm.advice.BaseAdvice.handle(BaseAdvice.kt:42)
at app//io.mockk.proxy.jvm.advice.jvm.JvmMockKProxyInterceptor.intercept(JvmMockKProxyInterceptor.java:31)
at app//io.reactivex.disposables.Disposable$Subclass2.equals(Unknown Source)
at app//io.reactivex.internal.util.OpenHashSet.add(OpenHashSet.java:64)
at app//io.reactivex.disposables.CompositeDisposable.add(CompositeDisposable.java:108)
at app//com.benoholding.beno.app.extensions.RxExtensionsKt.plusAssign(RxExtensions.kt:7)
at app//com.benoholding.beno.presentation.ui.features.more.account.accountInfo.AccountInfoViewModel.getAccountInfo(AccountInfoViewModel.kt:95)
at app//com.benoholding.beno.presentation.ui.features.more.account.AccountInfoViewModelTest.given init state , when getAccountInfoUseCase success , then active state should be emit(AccountInfoViewModelTest.kt:61)
at java.base@11.0.11/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base@11.0.11/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base@11.0.11/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base@11.0.11/java.lang.reflect.Method.invoke(Method.java:566)
at app//org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at app//org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at app//org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at app//org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at app//org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at app//org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at app//org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:61)
at app//org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:61)
at app//org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:61)
at app//org.koin.test.mock.MockProviderRule$apply$1.evaluate(MockProviderRule.kt:28)
at app//org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at app//org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at app//org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at app//org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at app//org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at app//org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at app//org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at app//org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at app//org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at app//org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at app//org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at app//org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
at java.base@11.0.11/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base@11.0.11/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base@11.0.11/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base@11.0.11/java.lang.reflect.Method.invoke(Method.java:566)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
at com.sun.proxy.$Proxy2.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker$2.run(TestWorker.java:176)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:133)
at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)

Context
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

MockK version:1.12.0
OS:windows
Kotlin version:1.6
JDK version:1.8
JUnit version:
Type of test: unit test
}

the function impletation
@test
fun given init state , when SaveAccountInfoUseCase fail , then SubmissionError state should be emit() {
// arrange
val accountInfo = fakePresentationAccountInfo()
saveAccountInfoUseCaseReturnFail()
// act
subject.saveAccountInfo()
// assert
val submissionError = AccountUiState.SubmissionError(accountInfo, "error")

Truth.assertThat(subject.uiUiState.value)
    .isInstanceOf(AccountUiState.SubmissionError::class.java)

}

the the code is
fun saveAccountInfo() {
val accountInfo = _uiState.value.accountInfo
disposable += saveAccountInfoDataUseCase.execute(
accountInfo.fromPresentationToDomain()
)

I have the same issue when using disposable +=. Please note that the test is flaky, sometimes it passes, sometimes it fails with the exception io.mockk.MockKException: can't find stub Disposable(temporary mock)

Context
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

MockK version: 1.12.2
OS: MacOS
Kotlin version: 1.5.31
JDK version: 1.8
JUnit version:
Type of test: unit test

@stale
Copy link

stale bot commented Jul 10, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If you are sure that this issue is important and should not be marked as stale just ask to put an important label.

@stale stale bot added the stale label Jul 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant