Spring-Boot 1.4 will introduce a new annotation for test classes called @SpringBootTest to avoid some of the integration test boilerplate annotations. See boot-features-testing-spring-boot-applications and Testing improvements in Spring Boot 1.4
Currently the spock-spring plugin does not recognize this annotation in order to identify this class as a Spring test class and instead relies on other annotations like @ContextHierarchy or @ContextConfiguration which do not need to be present if @SpringBootTest used.
I'm working on this in #582.
The other new annotations like @DataJpaTest or @WebMvcTest are not supported as well. What would be a good strategy to identify Spring instead of looking for specific annotations? This seems to be a bit unstable.
@kiview Do you have a proposal how the implementation could look like?
I'll try to look into Spring-Boot and see if I can find a more stable element to look for inside the classpath. I think checking for @BootstrapWith(SpringBootTestContextBootstrapper.class) might work.
I think I got it working by looking for an annotation which class itself is annotated with @BootstrapWith. I'll check if it works for all test annotations now and I'll submit an PR afterwards.
The PR is #610.
Right now it seem's, the new Spring-Boot tests have broken JDK6 compatibility, I'll look into that.
It's working now.
I believe there might still be an issue with @WebMvcTest, specifically when providing a controller with constructor arguments. Spring Boot documentation uses mockito and @MockBean however this won't work with Spock. While Spock does provide Mock() support it would seem that they are not being registered correctly.
@AlexejK Could you open a dedicated issue for this problem? Your explanation makes sense, but I think we need a special implementation for the @WebMvcTest annotation, since a bit more logic and plumbing is involved here.
The current solution simply restores Spock's Spring integration functionality to work like before Spring-Boot 1.4. The problem with @WebMvcTest however is an enhancement of the existing functionality I'd say.
I'd like to look into this problem as well, did you already look into the code? I'm not entirely sure yet if we can rework the existing behavior to work correctly with Spock or if we need a dedicated annotation, like @SpockWebMvcTest.
Sorry, should've thought about the separate issue.
Have not yet had a chance to see exactly what is happening - just spent time yesterday trying to make it work and found out it doesn't :( Anyways, #624 created for future discussions & tracking.
it seems to fix the issues that I had in my particular project, thanks.
Most helpful comment
I believe there might still be an issue with
@WebMvcTest, specifically when providing a controller with constructor arguments. Spring Boot documentation uses mockito and@MockBeanhowever this won't work with Spock. While Spock does provide Mock() support it would seem that they are not being registered correctly.