You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A mocked object's function which I am trying to change doesn't run before while I am calling every{}.
Current Behavior
The real function seems to be called while calling every{}.
Failure Information (for bugs)
Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.
Steps to Reproduce
Please provide detailed steps for reproducing the issue.
Run mockkObject on object provided by Emarsys Android SDK
Run every { emarsysObject.clearContact() } returns Unit
Get a crash because it actually runs the real implementation (clearContact())
Context
MockK version: 1.13.10
OS: macOS 14.4.1
Kotlin version: 1.9.23
JDK version: 17
JUnit version: 4.13.2
Type of test: unit test
Stack trace
// -----------------------[ YOUR STACK STARTS HERE ] -----------------------
(exception caused by the real implementation, expected if you run it without initializing it)
java.lang.IllegalStateException: DependencyContainer has to be setup first!
at com.emarsys.di.EmarsysComponentKt.emarsys(EmarsysComponent.kt:21)
at com.emarsys.di.EmarsysDependencyInjection.mobileEngageApi(EmarsysDependencyInjection.kt:24)
at com.emarsys.Emarsys.clearContact(Emarsys.kt:157)
at com.emarsys.Emarsys.clearContact$default(Emarsys.kt:152)
at com.example.mockkobjecttest.ExampleUnitTest$mockingEmarsys$1.invoke(ExampleUnitTest.kt:38)
at com.example.mockkobjecttest.ExampleUnitTest$mockingEmarsys$1.invoke(ExampleUnitTest.kt:38)
// -----------------------[ YOUR STACK TRACE ENDS HERE ] -----------------------
Minimal reproducible code (the gist of this issue)
// -----------------------[ GRADLE DEFINITIONS ] -----------------------
dependencies {
// Requires an android project / AGP
implementation("io.mockk:mockk:1.13.10")
implementation("com.emarsys:emarsys-sdk:3.7.5")
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs_nio:2.0.4")
}
// -----------------------[ YOUR CODE STARTS HERE ] -----------------------packagecom.example.mockkobjecttestimportcom.emarsys.Emarsysimportio.mockk.everyimportio.mockk.mockkObjectimportio.mockk.verifyimportorg.junit.TestclassIssue69Test {
@Test
funmockingEmarsys() {
val emarsysObject =Emarsys
mockkObject(emarsysObject)
every { emarsysObject.clearContact() } returns Unit
emarsysObject.clearContact()
verify(exactly =1) { emarsysObject.clearContact() }
}
}
// -----------------------[ YOUR CODE ENDS HERE ] -----------------------
The text was updated successfully, but these errors were encountered:
Prerequisites
Please answer the following questions for yourself before submitting an issue.
Repro Project
https://github.com/carstenhag/mockkobjectrepro/blob/master/app/src/test/java/com/example/mockkobjecttest/ExampleUnitTest.kt#L32
Expected Behavior
A mocked object's function which I am trying to change doesn't run before while I am calling
every{}
.Current Behavior
The real function seems to be called while calling
every{}
.Failure Information (for bugs)
Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.
Steps to Reproduce
Please provide detailed steps for reproducing the issue.
mockkObject
on object provided by Emarsys Android SDKevery { emarsysObject.clearContact() } returns Unit
clearContact()
)Context
Stack trace
Minimal reproducible code (the gist of this issue)
The text was updated successfully, but these errors were encountered: