-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Add JUnit 5 parameter resolver for @MockBean #13113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I can imagine Boot users requesting similar support for other Boot testing features such as |
Oh wait... I just realized that So there's nothing special to do there: the |
@sdeleuze, the challenge with supporting The question is what Boot would ultimately want to support for those annotations. Since the Spring TestContext Framework currently does not support loading of an In other words, I don't think it would make much sense to support those annotations on parameters for test methods or test lifecycle methods. |
Indeed my use case is only for constructor parameters. @ExtendWith(SpringExtension::class)
@WebMvcTest
class HttpApiTests(@Autowired val mockMvc: MockMvc) {
@MockBean
private lateinit var userRepository: UserRepository
@Test
fun foo() { }
} Versus @ExtendWith(SpringExtension::class)
@WebMvcTest
class HttpApiTests(@Autowired val mockMvc: MockMvc,
@MockBean val userRepository: UserRepository) {
@Test
fun foo() { }
} |
Yeah, we'd need to limit this because mocks == new context. |
@sdeleuze Is there any plan to support per-method ApplicationContext? |
This comment has been minimized.
This comment has been minimized.
Please use the 👍 and 👎 reactions on the issue description to indicate your interest rather than spamming the issue with comments. |
This comment was marked as off-topic.
This comment was marked as off-topic.
It would seem currently that the only option is to write a second test class since I only wanted to mock this for one test method. |
Given the plan to deprecate |
@wilkinsona do you guys have the ability to move tickets between spring projects? I know that GitHub added that ability a while back. Would it be possible simply to move (And reopen ) this issue over to the spring framework instead of having to have someone rewrite the whole thing? |
I don't, but some of the team do as they're commiters projects. @bclozel can please transfer this if appropriate or would the Framework team prefer a fresh issue? |
Like there is a parameter resolver for
@Autowired
, it would be useful to have one for@MockBean
, especially in Kotlin where it would enable usingval
instead oflateinit var
.cc @sbrannen
The text was updated successfully, but these errors were encountered: