question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add an example showing how to use AutoConfigureRestDocs with WebTestClient

See original GitHub issue

@AutoConfigureRestDocs used with WebTestClient causes the following NullPointerException:

java.lang.NullPointerException
	at java.util.HashMap.putMapEntries(HashMap.java:501)
	at java.util.HashMap.<init>(HashMap.java:490)
	at org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.retrieveConfiguration(WebTestClientRestDocumentation.java:143)
	at org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.lambda$document$0(WebTestClientRestDocumentation.java:80)
	at org.springframework.test.web.reactive.server.DefaultWebTestClient$DefaultBodyContentSpec.lambda$consumeWith$3(DefaultWebTestClient.java:540)
	at org.springframework.test.web.reactive.server.ExchangeResult.assertWithDiagnostics(ExchangeResult.java:197)
	at org.springframework.test.web.reactive.server.DefaultWebTestClient$DefaultBodyContentSpec.consumeWith(DefaultWebTestClient.java:540)
	at com.example.demo.web.UserControllerWithAutoconfigureDocTest.shouldGetUser(UserControllerWithAutoconfigureDocTest.java:31)

Here’s a complete minimal test case reproducing the problem: https://github.com/jnizet/webtestclientrestdocsissue

See the failing test, with the complete stack trace, in https://github.com/jnizet/webtestclientrestdocsissue/blob/master/src/test/java/com/example/demo/web/UserControllerWithAutoconfigureDocTest.java

The same test not using REST Docs passes: https://github.com/jnizet/webtestclientrestdocsissue/blob/master/src/test/java/com/example/demo/web/UserControllerTest.java

And the same test using REST docs but configuring it manually also passes: https://github.com/jnizet/webtestclientrestdocsissue/blob/master/src/test/java/com/example/demo/web/UserControllerWithApplicationContextDocTest.java

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
wilkinsonacommented, Feb 18, 2019

Thanks for the offer. The problem isn’t specific to WebTestClient and REST Docs’ MockMvc and REST Assured integration can fail in a similar way. I think it’s right that it fails and I don’t think that just adding a null check would be an improvement. It may, however, be an improvement to check for the configuration being null and, if it is, throwing something like an IllegalStateException that guides the user towards the integration with whatever testing client is in use being incorrectly configured.

0reactions
snicollcommented, Feb 27, 2019

Closing in favour of PR #15978

Read more comments on GitHub >

github_iconTop Results From Across the Web

46. Testing - Spring
You can use the @AutoConfigureRestDocs annotation to use Spring REST Docs in your tests with Mock MVC, REST Assured, or WebTestClient. It removes...
Read more >
spring-projects/spring-restdocs - Gitter
@wilkinsona So how would for example pretty print work with WebTestClient If I use @AutoConfigureRestDocs ?
Read more >
Spring Rest Docs with JUnit 5 and Webflux - Stack Overflow
I am using Spring Boot 2.1.3 with spring-restdocs-webtestclient as dependency. java · spring · spring-webflux · junit5 · spring- ...
Read more >
Document your API with Spring REST Docs - Igorski
Spring REST Docs setup. In this example we are going to use MockMVC and a Maven project. Based on that we will need...
Read more >
Documenting Spring Boot Restful Services (Spring ... - LinkedIn
Let's add pieces of code to that to document this method. Like I mention before, Spring REST docs uses our written tests to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found