Code Monkey home page Code Monkey logo

Comments (2)

Nillerr avatar Nillerr commented on August 14, 2024 1

Hi @lupuuss!

Happy to have come across another mocking framework for Kotlin Multiplatform!

The way we solved this in mockative/mockative was by recursively generating mocks (and default values) for the parameters of the default constructor. This also automatically enables implicit chain-mocking like this:

interface LibraryClient {
    val books: BooksRepository
}

val client = mock<LibraryClient>()

@Test
fun test() {
    everySuspend { client.books.findById(id) } calls { (id: String  -> Book(id) }
} 

This assumes the consumer is also using the all-open plugin. You may be able to do something similar in your Mokkery 🙂

from mokkery.

lupuuss avatar lupuuss commented on August 14, 2024

Hi @Nillerr!

Thank you for your kind words and the suggestion! I've started investigating this feature some time ago, and I think providing a default value for each parameter is sufficient to make it work and generating mocks recursively seems like an overhead. Also, reusing it for the chain-mocking would still require extra effort to make this feature work. Moreover, I'm not sure if implementing chain-mocking is worth the effort as the syntax below might be "good enough":

every { client.books } returns mock {
    everySusend { findById(any()) } calls { (id: String) -> Book(id) }
}

What do you think about it?

from mokkery.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.