s1m0nw1
04/16/2019, 10:10 AMmben
04/17/2019, 2:45 PMMike
04/24/2019, 2:14 PMigorvd
05/14/2019, 7:36 PMclass ViewModel {
fun loadSomeStuff() {
myObject.asyncOperation(object : Callback {
//callback methods implementation
})
}
}
I know if I change the callback for a parameter in my class, it will be easily mocked. But, in my opinion it doesn't make sense, because it's related to the operation I need in the method.
(This example is just for learning purposes, I was trying to teach a colleague about unit tests, and I got stocked in this scenario)Sergio Crespo Toubes
05/16/2019, 12:49 PMverify(exactly = 1) { mView.loadUser(user is {name = "sergio"}) }
and not verify(exactly = 1) { mView.loadUser(user)}
Sergio Crespo Toubes
05/20/2019, 3:08 PMoleksiyp
05/23/2019, 1:29 PMwbertan
05/23/2019, 2:07 PMInstant.parse("2017-11-01T11:04:56Z")
before the mockkStatic
.kluck
06/05/2019, 9:03 AMverify(exactly = 1)
inside a kotlintest BehaviorSpec
, but it fails as it doesn't seem to be isolated from my other Given
scope. Here's a basic example:
Given("foo") {
every { persistentSource.getAccessToken() } returns IO.raiseError(exception)
When("") {
[...] Then [...]
}
}
Given("foo2") {
every { persistentSource.getAccessToken() } returns IO { smartphonePersistedAccessToken }
When("") {
[...]
Then("") {
verify(exactly = 1) { persistentSource.getAccessToken() }
}
}
}
svenjacobs
06/12/2019, 9:57 AMclass CouponListInteractor(
private val isCouponSelectedUseCase: IsCouponSelectedUseCase
) {
suspend fun isCouponSelected(uuid: String) = isCouponSelectedUseCase.execute(uuid)
}
object CouponListInteractorTest : Spek(
{
val isCouponSelectedUseCase by memoized {
mockk<IsCouponSelectedUseCase> {
coEvery { execute(any()) } returns false
coEvery { execute("uuid") } returns true
}
}
val interactor = CouponListInteractor(
isCouponSelectedUseCase
)
describe("CouponListInteractor") {
context("isCouponSelected") {
it("should return coupon selected state") {
runBlockingTest {
interactor.isCouponSelected("uuid") shouldEqual true
}
coVerify {
// ERROR: Bad recording sequence. State: AnsweringState
isCouponSelectedUseCase.execute("uuid")
}
}
}
}
}
coVerify
produces Bad recording sequence. State: AnsweringState
. However when I replace interactor.isCouponSelected("uuid") shouldEqual true
with isCouponSelectedUseCase.execute("uuid") shouldEqual true
the test runs. isCouponSelected()
just delegates to the use case. I don't understand this behaviour? 🤯sdeleuze
06/12/2019, 11:46 AMopen
classes/methods where Mockito is significantly fasterDariusz Kuc
06/12/2019, 11:00 PMclass MockkCaptorTest {
@Test
fun `verify mockk captor behavior`() {
val simpleMockk = mockk<Simple> {
every { hello(any(), any()) } answers { "Mocked response for ${arg<String>(0)}, age: ${arg<Int>(1)}" }
}
simpleMockk.hello("Bob", 2)
simpleMockk.hello("Alice", 1)
val bobsAge = slot<Int>()
verify {
simpleMockk.hello("Bob", capture(bobsAge))
}
assertEquals(2, bobsAge.captured)
}
}
class Simple {
fun hello(name: String, age: Int) = "Hello $name, age: $age"
}
above will actually capture Alice
ageDavide Giuseppe Farella
06/16/2019, 3:00 PMMatt Thompson
06/17/2019, 11:00 PMArtur Borowy
06/18/2019, 9:13 AMverify(exactly = 1, verifyBlock = { mock.method{ lambdaArgument() } })
Joan Colmenero
07/03/2019, 7:31 PMattachView
and detachView
on my Presenter do I have to test these methods? Inside of the presenter I have the loadData
and I have the unit tests for this loadData
but then I have these methods and I don't know if I have to unit test those or notJoram Visser
07/09/2019, 10:54 AMfoo
and bar
in this example.
The code in the snippet is not working. I also tried making use of mockkConstructor()
function for the ServiceLocator()
, Foo()
and Bar()
, which also didn’t work.
So my question is; how can I set up the mocks correctly so that I can test MyClass
without going out of the class.Karolis
07/15/2019, 8:59 AMval slot1 = slot<InvoiceLateFeeEntry>()
verify {
repo.save(capture(slot1))
}
val slot2 = slot<InvoiceLateFeeEntry>()
verify {
repo.save(capture(slot2))
}
slot1 == slot2, yet repo.save()
was walled with different argumentsoleksiyp
07/17/2019, 6:57 AMoleksiyp
07/17/2019, 1:37 PMconfirmVerified
oleksiyp
07/17/2019, 2:31 PMAnthony f
07/18/2019, 2:24 PMbbaldino
07/25/2019, 5:42 PMprivate val dummyPacket = mockk<RtpPacket> {
every { this@mockk getProperty "payloadType" } returns originalPayloadType
every { this@mockk getProperty "ssrc" } returns originalSsrc
}
LeoColman
08/10/2019, 1:17 PMsvenjacobs
08/14/2019, 1:40 PMval fn: () -> String? = mockk {
// not working since "invoke()" clashes with invoke() function from MockK
every { invoke() } returnsMany "hello", null
}
Anthony f
08/23/2019, 2:20 PMAlessandro Tagliapietra
08/27/2019, 6:41 AMmockkObject
to mock an object, since it's an object that makes external requests, is it possible to have the mocked version return an error if a method isn't mocked?oleksiyp
09/03/2019, 12:54 PMthanksforallthefish
09/18/2019, 7:31 AMfun updateParticipant(participant: Participant, update: Participant.() -> Unit)
?
I am trying with
val participantOrchestrationService: ParticipantOrchestrationService = mockk(relaxed = true)
val dummy = Participant()
val update = slot<Participant.() -> Unit>()
every { participantOrchestrationService.updateParticipant(dummy) { capture(update) } } just Runs
update.captured(dummy)
dummy should {
it.state == State.inactive
}
but getting kotlin.UninitializedPropertyAccessException: lateinit property captured has not been initialized
any suggestion?Kamil K
09/20/2019, 8:50 AM1.3.2
with mockk
and mockk-android
1.8.3