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.

Diagnostics are poor when using JUnit 5 and accidentally using @BeforeAll rather than the required @BeforeEach

See original GitHub issue

Hi,

I updated a project with spring-boot-dependencies to 2.0.4.RELEASE this morning, which in turn updated spring-restdocs dependency to version 2.0.2.RELEASE (upgraded from 2.0.1.RELEASE). I am also using spring-restdocs-restassured.

The version update of spring-restdocs to 2.0.2.RELEASE seems to cause the following issue when invoking requestSpec.when().get("/myUri"):

java.lang.NullPointerException
	at org.springframework.restdocs.ManualRestDocumentation.beforeOperation(ManualRestDocumentation.java:89)
	at org.springframework.restdocs.RestDocumentationExtension.lambda$resolveParameter$0(RestDocumentationExtension.java:58)
	at org.springframework.restdocs.restassured3.RestAssuredRestDocumentationConfigurer.filter(RestAssuredRestDocumentationConfigurer.java:69)
	at org.springframework.restdocs.restassured3.RestAssuredOperationPreprocessorsConfigurer.filter(RestAssuredOperationPreprocessorsConfigurer.java:46)
	at io.restassured.filter.Filter$filter.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:144)
	at io.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:72)

From a quick debugging, I could find that ManualRestDocumention doesn’t have a context (is null) when RestDocumentationExtension.resolveParameter(...) invokes beforeOperation(). I also found that RestDocumentationExtension was modified in 2.0.2.RELEASE.

When I force spring-restdocs dependencies to version 2.0.1.RELEASE (while keeping spring-boot-dependencies to version 2.0.4.RELEASE), the issue goes away.

See also, stackoverflow post

Thanks.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
wilkinsonacommented, Aug 6, 2018

Thank you, @sbrannen!

0reactions
sbrannencommented, Aug 6, 2018

Note: I’m not condoning the use of @BeforeEach and @AfterEach on a @Test method. 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

JUnit 5 does not execute method annotated with BeforeEach
In my case the problem was that the @Test annotation was taken from wrong import. Originally it was imported from org.junit.Test .
Read more >
Before vs @BeforeClass vs @BeforeEach vs @BeforeAll
In this short tutorial, we're going to explain the differences between the @Before, @BeforeClass, @BeforeEach and @BeforeAll annotations in ...
Read more >
JUnit 5 User Guide
Beginning with Java 16, @BeforeAll and @AfterAll methods can be declared as static in a @Nested test class with either test instance lifecycle ......
Read more >
Testing | HCL Project KEEP - Open Source
JUnit 5 uses the org.junit.jupiter.api packages. Tests are annotated (as usual) with @Test . @DisplayName can be used to give a nice display...
Read more >
Deep Dive into JUnit 5 Extension Model - InfoQ
JUnit 5 is a modular and extensible testing framework with support for Java 8 and higher. The Jupiter extension model can be used...
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