Comments (9)
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.
Since we are going to leverage Spring Boot, mockito-kotlin
2 is probably a better option.
from spring-fu.
@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.
Added a ticket mockk/mockk#118
from spring-fu.
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.
Syntax looks good to me. Mockk was designed to have few front facing DSLs via so called Gateway API
from spring-fu.
I have created #151 for a Kofu equivalent of @MockkBean
.
from spring-fu.
@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.
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)
- Upgrade to Spring Boot 2.4.4
- Rename master `branch` to `main`
- Upgrade to Spring Boot 2.5.1
- Ability to create endpoints/routes dynamically (IE and endpoint creating another endpoint at runtime)?
- enable function is protected HOT 1
- spring-boot-autoconfigure conflit HOT 1
- Cannot extend Kotlin DSL HOT 1
- Upgrade to Spring Boot 2.5.3
- CoroutineCrudRepository issue
- Spring Native compatibility HOT 1
- Is the project discontinued? HOT 4
- [question] is Spring Fu production ready? HOT 1
- Upgrade to Spring Boot 2.6
- Build uses jcenter() which is deprecated and will be removed in Gradle 8
- Spring Kofu 0.5.0 issue with Spring Native HOT 1
- Project timeline HOT 2
- Upgrade to Spring Boot 2.6.6
- R2dbc H2 does not work with Spring Boot 2.7 HOT 1
- Activate Autoconfiguration for certain external dependencies HOT 1
- Spring Boot 3.0.0 seems to break kofu HOT 16
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-fu.