-
Notifications
You must be signed in to change notification settings - Fork 736
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
Nullpointer Exception when using JUnit 5 @Nested tests #490
Comments
Thanks for the sample. The Note that these problems are specific to |
Just want to check in on the status of this issue. It seems the limitation mentioned above with junit 5 We have a lot of tests in Manually configure mockMvc with rest docs might not be an easy option, as there's a large gap to be filled, as mentioned #41 (comment). We do have spring security filters that is not included by default when going manual. |
Thanks @wilkinsona for the response. I thought it might still be a known issue so I just tried to confirm. Knowing it isn't, I just created a quick demo branch: https://github.com/lzhoucs/spring-restdocs/tree/junit5-nested-issue-demo where I modified the @SpringBootTest
@AutoConfigureMockMvc
@AutoConfigureRestDocs
public class SampleJUnit5ApplicationTests {
@Autowired
private MockMvc mockMvc;
@Test
public void sample() throws Exception {
mockMvc.perform(get("/hello"))
.andExpect(status().isOk())
.andDo(document("sample"));
}
@Nested
class NestedTests {
@Test
public void sampleNested() throws Exception {
mockMvc.perform(get("/hello"))
.andExpect(status().isOk())
.andDo(document("sample"));
}
}
}
|
The configuration you've tried doesn't match the recommendations above.
With the configuration that you've shared, You can avoid the problem by configuring your nested class like this: @Nested
@SpringBootTest
@AutoConfigureMockMvc
@AutoConfigureRestDocs
class NestedTests {
@Autowired
MockMvc mockMvc;
@Test
public void sampleNested() throws Exception {
this.mockMvc.perform(get("/"))
.andExpect(status().isOk())
.andDo(document("sample"));
}
} You need to inject This doesn't feel right to me, but it's out of the control of Spring REST Docs. @sbrannen how are nested tests expected to work in Framework 5.1? What configuration is required to have a nested test reuse the context, test execution listeners, etc from its outer class? |
The behavior is 5.1 is the same as in 5.0. The current goal is to address this in 5.2: spring-projects/spring-framework#19930 |
Hello Spring REST Docs Team!
It seems that JUnit 5's
@Nested
tests don't work with auto-configured Spring REST Docs.Executing the following simple test class will result in a
NullPointerException
:The resulting stacktrace:
Tested with Spring Boot
2.0.1.BUILD-SNAPSHOT
, Spring REST Docs2.0.0.RELEASE
and JUnit5.1.0
on2018-03-14
at around 11:00 PM.I created a simple example application (thx start.spring.io ;) ) to reproduce the issue:
https://github.com/slu-it/bug-spring-restdocs-nested-tests
Note: This might be related to the following issue I opened in Spring Boot:
spring-projects/spring-boot#12470
The text was updated successfully, but these errors were encountered: