Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Oleksiy Pylypenko
    @oleksiyp
    interesting
    not sure about spek
    never heard anything about interference
    Anderson Reinkordt
    @son1112
    context("with valid data") {
                    mockHappyPath()
    
                    it("is successful") {
                        assertEquals(true, baseTransactionSlot.isCaptured)
                        assertEquals(merchantAccountMock, baseTransactionSlot.captured.merchantAccount)
                    }
                }
                context("with invalid data") {
                    context("with invalid amount") {
                        mockHappyPath(amountValue = 0)
    
                        it("is not successful") {
                            assertEquals(false, baseTransactionSlot.isCaptured)
                        }
                    }
                }
    Oleksiy Pylypenko
    @oleksiyp
    may be
    it runs it in parallel
    ?
    Anderson Reinkordt
    @son1112
    it's possible
    Oleksiy Pylypenko
    @oleksiyp
    then some way to isolate mocks should exists
    alike any other object
    Anderson Reinkordt
    @son1112
    if i switch those mockHappyPaths in which I call variable every stubs, the last one is the one that remains and the failures flip around
    I'll look into spek more to see how it runs
    Oleksiy Pylypenko
    @oleksiyp
    the only question is how you store variable for mock
    and if it is shared between test
    if so you need to somehow split it
    and share only code that initialize mock
    Anderson Reinkordt
    @son1112
    val amountMock: Amount = mockk()
    every { amountMock.bigDecimalValue() } returns BigDecimal(amountValue)
    Oleksiy Pylypenko
    @oleksiyp
    yes
    but where amountMock is placed
    in which scope
    Anderson Reinkordt
    @son1112
    beforeEachTest {
                    transactionManager.createSale(
                        context = contextMock,
                        amount = amountMock,
                        merchantAccount = merchantAccountMock,
                        callbackUrl = callbackUrl,
                        metadata = metadata,
                        isSignatureRequired = isSignatureRequired,
                        isQuickChipEnabled = isQuickChipEnabled,
                        handler = handlerMock,
                        onComplete = onCompleteMock
                    )
                }
    Oleksiy Pylypenko
    @oleksiyp
    probably you need to put mock creation
    into this block
    beforeEachTest
    Anderson Reinkordt
    @son1112
    interesting
    will try that
    Oleksiy Pylypenko
    @oleksiyp
    you can always create some function that accepts mock and do the same thing
    I mean
    do a same sequence of every to intialize mock
    but with creating and storing mock itself you need to be careful
    as spek probably indeed run it in parallel
    Ashutosh
    @apendse
    I have written a few tests in Android where I am using Mockk to mock some objects. I am running into an issue that when I run the whole test suite, the tests fail with a crash but when I run each test separately, it works fine. Is there some cleanup required between the tests?
    Ashutosh
    @apendse
    The stack trace shows that Mockk injects a class that acts like contextWrapper and that's causing the failure.
    Oleksiy Pylypenko
    @oleksiyp
    It might be the case that some classes are crtitical to the system and mocking them going to cause instability. Please minimize your example and submit it as a github issue if you think this should be fixed in the future
    asaidalaoui
    @asaidalaoui

    Hello I am new to using Mockk.

    I am trying to mock an object however I keep getting the following error io.mockk.MockKException: Missing calls inside every { ... } block.

    I am guessing this should be pretty straight forward

    @BeforeEach
        fun setup() {
            mockkObject(FilterFactory)
        }
    
        @Test
        fun `should return an unmatched filter result if there is no context match`() {
            every { FilterFactory.getFilters("invalid") } returns emptyList()
        }
    Andriy Matkivskiy
    @amatkivskiy
    Hi all, is there any way to verify that every call mocked with every { } was called ?
    As far as I know such approach is implemented in Mockito and called strict mode
    Andriy Matkivskiy
    @amatkivskiy
    Is there any similar functionality in Mockk?
    Joakim Forslund
    @Syrou
    So Im trying to mockk a class which has constructor parameters, it seems like mockk is not able to override these variables for som reason because they are empty when I later try to use a method to log if they have been set or not.
    How do I create a mockked class what I also have specified constructor parameters on?
    Oleksiy Pylypenko
    @oleksiyp
    This is not implemented yet
    iulianrosca
    @iulianrosca

    Hello, I have the following question related to returning an instance of a final class from a spyk. I have the following code:

    val foo = Foo()
    val spyFoo = spyk(foo)
    val instanceOfFinalBar = BarFactory.createInstance() // interop with final Java class with package private constructors
    every {spyFoo.bar } returns instanceOfFinalBar

    The above fails with:

    java.lang.VerifyError
        at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
        at sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:144)
        at io.mockk.proxy.jvm.transformation.JvmInlineInstrumentation.retransform(JvmInlineInstrumentation.kt:28)
        at io.mockk.proxy.common.transformation.RetransformInlineInstrumnetation$execute$1.invoke(RetransformInlineInstrumnetation.kt:19)
        at io.mockk.proxy.common.transformation.RetransformInlineInstrumnetation$execute$1.invoke(RetransformInlineInstrumnetation.kt:6)

    Any clues what I'm doing wrong? I assume it's related to the fact that Bar is final. I was expecting you cannot mock a final class, but you can return an instance of a final class from a mock.

    Mark Robinson
    @MarkRobbo
    Hi - trying to mock a call to Clock.instant() to return progressively increasing Instants (in a more generic way, returning subsequently different answers for the same call). Is this possible with mockk?
    Mark Robinson
    @MarkRobbo
    Never mind found it, returnsMany or andThen
    Stanislav Kinzl
    @mageRabbitStudios
    Hello, I'm trying to add mockk-android dependency of version 1.9.3 for some time now. I want it in order to statically mock getCurrentTimeMillis function in System, so I can override the current time the device returns, so I can snapshot test some cards we have in our app in different states (expires soon etc...). But I'm unable to do that because every time I try to sync project after adding the 'androidTestImplementation "io.mockk:mockk-android:1.9.3"' into the gradle, I get "Unable to resolve dependency" error. I don't get the error for normal mockk (I already used it in the project). I'm I missing something? Thank you.
    alsamwright
    @alsamwright
    Hi - having an issue with a verify(exactly =) call. I have 2 tests that individually mock the same the same method, in one case to return true and in the other to return false. In the former case I'm verifying that the mock is called an exact number of times, in the latter case the number of calls is not a concern. If I run the tests individually there is no problem, they work as expected. However, if I run the full suite then the verify fails because it includes the count for the second case. Is there a way to reset the count for verify between test methods? (The tests are in a Junit5 @Nested block)
    alsamwright
    @alsamwright
    Immediately after posting this I found the following solution - @BeforeEach
    fun clear() {
    clearMocks(myMock)
    }
    Karthick Chinnathambi
    @ckarthickit2
    Hi ,
    I have a class with private constructor and exposed a public Builder that instantiates the class
    how can i verify if the private constructor is invoked with specified params ?
    Bulat Galeev
    @bulatgaleev
    @oleksiyp Greetings. My colleague wants to contribute. Does it needed to be discussed first here or somewhere else or he can just make a PR?
    MagoMtzAl
    @MagoMtzAl

    Hi everybody, i'm having problems trying to test an Observable with concatMap and then compose. The function i want to test looks like:

    interactor?.let { interactor ->
    interactor.isServerConfigurationEmpty().concatMap { isEmpty ->
    if (isEmpty)
    Observable.just(ClientTO())
    else
    Observable.just(false)
    }.compose(schedulerProvider.ioToMainObservableScheduler())
    .subscribe({ res -> ... }, {})

    How should i mock the result for interactor.isServerConfigurationEmpty() and interactor.isServerConfigurationEmpty().compose(...)
    I have post a question in stackoverflow if someone wants to check it.
    https://stackoverflow.com/questions/58032630/android-how-to-unit-test-observable-concatmap-compose-with-mockk