-
Notifications
You must be signed in to change notification settings - Fork 84
Provide module-scoped equivalents to @WebMvcTest and @DataJpaTest #5
Comments
@WebMvcTest
and @DataJpaTest
Ideally, I'd love to see the annotations to work properly in combination rather than having to replicate all of them into this project. I guess that's currently not working properly as Boot is not expecting multiple of these annotations to be used at the same time. I'll take this request forward to the Boot team to see what we can do here. |
With "in combination", you mean "in combination with @RunWith(SpringRunner.class)
@DataJpaTest
@ModuleTest
public class MyModuleDataLayerTests {
// ...
} |
Exactly. Did you try that already? |
Did so just now: @RunWith(SpringRunner.class)
@WebMvcTest
@ModuleTest
public class BookingControllerTest {
...
} leads to
|
Interesting. Does it also fail in this way if you use e.g. @wilkinsona – it looks like Spring's |
I've created the following JIRA issue to address this (at least partially). https://jira.spring.io/browse/SPR-17006 Feedback on the JIRA issue is welcome. |
I actually just introduced a test for "the same" use case, and that already works since For example, the bootstrapper resolved for @BootstrapWith(FooBootstrapper.class)
@Retention(RetentionPolicy.RUNTIME)
@interface BootWithFoo {}
@BootstrapWith(FooBootstrapper.class)
@Retention(RetentionPolicy.RUNTIME)
@interface BootWithFooAgain {}
@BootWithFoo
@BootWithFooAgain
static class DuplicateMetaAnnotatedBootstrapWithAnnotationClass {} Thus, it would appear that only the "compatible" use case is not supported. Can you confirm that? |
For the new test, see: spring-projects/spring-framework@755add3 |
According to Sam, |
Yes, |
OK. Thanks for the confirmation. |
@olivergierke, do you think you still need new support for the "compatible" use case in the TCF? |
@sbrannen – Ultimately, yes. I'd love to get the input of the Boot team (@wilkinsona, @philwebb) on whether using these annotations in combination is something they're intending to work towards. I totally understand that the annotations that Boot currently ships don't really create that scenario. @thombergs – Re #4, did you see my comment there? |
@sbrannen – I've just tried a naive attempt for disambiguation by explicitly declaring an @RunWith(SpringRunner.class)
@DataJpaTest
@WebMvcTest
@BootstrapWith(WebMvcTestContextBootstrapper.class)
public class SomeTest { … } Is making that work maybe a cheap intermediate solution? |
OK. Then I'll hold off until the Boot team provides feedback in this regard. |
By "that" do you mean favoring a locally declared annotation over a meta-annotation on a locally declared composed annotation? |
Oh wait.... embarrassing... just read your lead-in comment. 😇 |
In any case, to answer your question.... See https://jira.spring.io/browse/SPR-12602. That was an issue raised by @philwebb to ensure that multiple competing declarations of |
In light of SPR-12602, that would be a breaking change. So I'm not so sure we should do that....... |
I’d argue it wouldn’t. The same code would still fail with the same error message. It would only allow the developer to resolve the ambiguity by adding an explicit override. |
mmmm... The meta-presence of more than one such annotation would continue to be an error. So in that sense, I suppose you're correct. Plus, if anyone had previously tried what you tried above, that would have failed then, and they would have stopped doing it. So, yeah, it wouldn't actually be a breaking change to any "working" code. Rather, it would be a change in behavior that someone would have to opt in for. In other words, I agree. 😉 |
Looks like @sbrannen was kind enough to add support for an escape hatch by adding an explicit annotation on the test class in Spring Framework 5.1. Would you mind giving this another look on 5.1, @thombergs? |
I just tried to verify this with In addition I tried to use |
I just realized that the test works when I specify all three together
But what does this mean for the bootsrapping? Does it initialize the whole application or only the current module? |
With
@WebMvcTest
and@DataJpaTest
we can easily create an ApplicationContext for the web- or data layer of our Spring Boot Application.It would be nice to have equivalents to these annotations that only include the web- or data layer of our module under test into the ApplicationContext.
Same goes for the other annotations like
@WebfluxTest
,@JdbcTest
and so on (see https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html).The text was updated successfully, but these errors were encountered: