Helio
01/15/2021, 9:46 PMPatrick Ramsey
02/11/2021, 10:18 PMMattia Tommasone
02/11/2021, 10:22 PMMattia Tommasone
02/13/2021, 2:57 PM1.10.6
has just been released: it has a good number of bugfixes, feel free to check it out!vio
03/02/2021, 1:11 PMgradle :test
). when run individually with kotest
runs perfectly. I have something like this:
beforeSpec {
Application.start()
mockkObject(MyObjectClass)
every { MyObjectClass.getRandomString() } returns "call made"
})
afterSpec {
clearAllMocks()
Application.stop()
}
....
// some other tests that should make calls to the function that I mocked above
"verify mockk" {
verify(exactly = 7) {
MyObjectClass.getRandomString()
}
}
I can't figure out what could be wrong here, I get this error when run from the command line :
java.lang.AssertionError: Verification failed: call 1 of 1: MyObjectClass(object MyObjectClass).getRandomString()) was not called .......
Any help is appreciated, thank you! 🙏Melih Aksoy
03/04/2021, 3:49 PMprocess
.inputStream
.bufferedReader()
.useLines { seq ->
val summary = seq.find { line -> line.contains(KEY_PACKET_LOSS) }
if (summary != null) {
val loss = packetLoss(summary)
val result = when {
loss > acceptablePacketLoss -> Stability.UNSTABLE
loss == MAX_LOSS -> Stability.NO_CONNECTION
else -> Stability.STABLE
}
continuation.resumeIfActive(result)
} else {
continuation.resumeWithExceptionIfActive(
IllegalStateException("Couldn't find result line in ping command")
)
}
}
I added required statics, but bufferedReader
and useLines
are inline methods… can I work this around somehow ?Daniele Andreoli
03/09/2021, 9:42 PMResponse.success(mockedResponseList)
Here's the code complete:
coEvery { restApi.getAllBeersWithPagination(1, null).hint(Response::class) } coAnswers { Response.success(mockedResponseList)}
But it always returns:
java.lang.ClassCastException: java.lang.Object cannot be cast to retrofit2.Response
Someone can help me, please? ThanksLuiz Aguiar
03/20/2021, 11:30 AMfun <T : Any> myFunction(foo: Foo, bar: Bar, response: KClass<T>): MyResponse<T> { do magic }
how can it be mocked to control the returned object?
I tried something like:
every { mockedClass.myFunction(any(), any(), ofType(SomeType::class) } returns SomeType()
but it didn't work... and using the type directly, myFunction(any(), any(), SomeType::class)
is never matched.Mattia Tommasone
04/08/2021, 2:47 PMivano
04/08/2021, 2:55 PMprivate fun getEmployees(users: List<String>)
takes a list that(also I mocked) which has two values “1” and “3"Patrick Ramsey
04/13/2021, 5:26 AMverify {
someMethod(capture(mySlot), "Some specific value")
}
Is there any way to actually just capture the value from when someMethod() was called with “Some specific value”? Or will that capture() match every single call, even the ones where the whole expression doesn’t match?Sergio Crespo Toubes
04/13/2021, 10:50 AManswers {
thirdArg<(String) -> Unit>().invoke("text")
}
i had to change it to
answers {
thirdArg<(String) -> Boolean>().invoke("text")
}
but i am getting the next solution Unit cannot be cast to java.lang.Boolean
any idea? thanksivano
04/20/2021, 2:53 PMobject AnalyticsReporter {
fun logEvent(message: String, bundle: Bundle = Bundle.EMPTY) {
FirebaseAnalytics.getInstance(ProActiveApplication.applicationContext()).logEvent(message, bundle)
}
the method i call is this one :
when (loginState.value) {
is EnterPassword -> {
unknownPassword.onNext(AuthenticationCredentials(client, emailAddress))
logEvent("user_forgot_password")
}
}
poohbar
04/20/2021, 8:10 PMAnton Afanasev
05/06/2021, 4:50 PMAnton Afanasev
05/07/2021, 2:59 PMVerification failed: calls are not exactly matching verification sequence
which is fine.
However the error message is not descriptive.
It points to the high level problem (something wrong with whole sequence) instead of saying something like: "Hey, your sequence failed because of argument matching here"
Are there a way to get more descriptive message when something like that happens? Is it me that incorrectly structure the test.
Attaching simplified version of the test:
@Test
fun `when connect`() {
// When
subject.connect()
// Then
verifySequence {
mockStateListener(State.CONNECTING)
mockPlatformSocket.openSocket(any())
}
}
And the error:
Verification failed: calls are not exactly matching verification sequence
Matchers:
Function1(#1).invoke(eq(CONNECTING)))
+PlatformSocket(#2).openSocket())
Calls:
1) Function1(#1).invoke(CONNECTED)
2) +PlatformSocket(#2).openSocket()
Stack traces:
André Thiele
05/09/2021, 3:37 PMPeter Ertl
05/18/2021, 11:49 AMPatrick Ramsey
05/18/2021, 5:11 PMWARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access using Lookup on io.mockk.proxy.jvm.ClassLoadingStrategyChooser (file:/home/circleci/.gradle/caches/transforms-2/files-2.1/5bf8247b5024cc1f3e5041b83c85dfb2/jetified-mockk-agent-jvm-1.10.6.jar) to class javax.xml.parsers.DocumentBuilder
WARNING: Please consider reporting this to the maintainers of io.mockk.proxy.jvm.ClassLoadingStrategyChooser
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Not sure if it’s related, but four tests then fail with NoClassDefFoundException: io/mockk/proxy/jvm/advice/jvm/JvmMockKProxyInterceptorAnton Afanasev
05/19/2021, 2:06 PMeurycea
05/21/2021, 1:37 PMRobert MacLean
05/27/2021, 8:41 AMmockk<T>(relaxed = true)
vs. spyk
?
I tend to think of them as the same and use the former is useful for when there is a default constructor and the the latter if I need to pass properties to a constructor, and otherwise think they end up the same…. but maybe I am wrong?Sourabh Rawat
06/01/2021, 4:08 AMCaused by: io.mockk.MockKException: Failed matching mocking signature for
SignedCall(retValue=java.lang.Object@32bb09d9, isRetValueMock=true, retType=class kotlin.Any, self=UseCase(#25), method=execute(Any, Continuation), args=[kotlin.Unit, Continuation at com.expediagroup.ord.fbs.usecase.UseCaseExecutorTest$2$1.invokeSuspend(UseCaseExecutorTest.kt:47)], invocationStr=UseCase(#25).execute(kotlin.Unit, continuation {}))
left matchers: [any()]
what could be the issue…Emil Kantis
06/01/2021, 8:45 PMPatrick Ramsey
06/04/2021, 7:32 PMPatrick Ramsey
06/04/2021, 7:32 PMEmil Kantis
06/10/2021, 7:28 PMPoint
data class Point(val x: Int, val y: Int)
val x = 7
val mockPoint = mockk<Point> {
every { x } returns x
}
If the receiver in the every
block would be <T> (or Point in this case), I believe x would bind correctly, but perhaps that causes other issues?Anton Afanasev
06/23/2021, 1:07 PMmkrussel
06/29/2021, 1:16 AMio.mockk.MockKException: can't find property workerHandler for dynamic property get
Mark Allanson
06/29/2021, 8:20 AMspyk
intercept all calls to object AND make it relaxed at the same time?