GithubHelp home page GithubHelp logo

Comments (9)

sdeleuze avatar sdeleuze commented on June 7, 2024 1

It turned out to be quite easy and powerful since we now can customize an existing app with any DSL in an additive configuration mode, only beans { } have the isPrimary = true capability for now.

val app = application {
    beans {
        bean { Bar("original") }
    }
}
app.customize {
    beans {
        bean(isPrimary = true) {
            mockk<Bar> {
                every { value } returns "customized"
            }
        }
    }
}

from spring-fu.

sdeleuze avatar sdeleuze commented on June 7, 2024

Since we are going to leverage Spring Boot, mockito-kotlin 2 is probably a better option.

from spring-fu.

sbuettner avatar sbuettner commented on June 7, 2024

@sdeleuze do you know if there is a plan to allow the usage of spring tests @MockBean with mockk?

Or maybe thats not even needed if there was an equivalent DSL for mocking beans in tests like

fun beforeAll() {
  app.run(profiles = "test").beans {
    mock<Foo>() 
    mock<Bar>().every { ... }
  }
}

Updated: Just saw you posted another comment (while I was writing this) regarding mockito-kotlin 2 which would work with @MockBean I guess. Nontheless a programmatic approach to mock beans could be a nice addition to avoid annotations.

from spring-fu.

oleksiyp avatar oleksiyp commented on June 7, 2024

Added a ticket mockk/mockk#118

from spring-fu.

sdeleuze avatar sdeleuze commented on June 7, 2024

I finally had some times to play with Mockk, and it is now clear to me that it is what we should promote on Spring side to Mock beans in Spring applications written in Kotlin. @jnizet has created a nice @MockBean like support for Mockk with its springmockk, it will not be integrated for now in Spring Boot even if there is a big demand for that because current infra is sadly Mockito specific. But we can move forward on Spring Fu side by thinking what is missing for such first class support.

I think @sbuettner proposal about allowing to customize an existing application is interesting, and would be useful for other use case than mocking. We could maybe support something like as a first step:

fun beforeAll() {
  app.beans {
    bean { mock<Foo>(isPrimary = true)  }
    bean { mock<Bar>(isPrimary = true).every { ... } }
  }.run(profiles = "test")
}

Then as a second step (with another dedicated issue) we could provide a functional Mockk equivalent to @MockBean like beans { mockBean<Foo>() }.

Any thoughts?

from spring-fu.

oleksiyp avatar oleksiyp commented on June 7, 2024

Syntax looks good to me. Mockk was designed to have few front facing DSLs via so called Gateway API

from spring-fu.

sdeleuze avatar sdeleuze commented on June 7, 2024

I have created #151 for a Kofu equivalent of @MockkBean.

from spring-fu.

sbuettner avatar sbuettner commented on June 7, 2024

@sdeleuze I like your approach as it uses the default infra to register mocks.

I could still see an extension method inside the beans {} context like mockk<Foo> {...} that internally calls bean(isPrimary = true) as this seems the be the main usage. A scenario where a mocked bean should not be registered as the primary one seems to be exception. As isPrimary in this case would have the default value of true one can always override it with false.

from spring-fu.

sdeleuze avatar sdeleuze commented on June 7, 2024

Since for now we recreate context every time with no specific caching involved, we can indeed maybe provide a simple mockkBean alias without having to invloved all the @MockkBean infrastructure. Let's discuss that as part of #151.

from spring-fu.

Related Issues (20)

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.