eclipse-ee4j / eclipse-ee4j/jersey

JerseyTest is not compatible with JUnit 5

Open
#3,662 9 comments 15 reactions 0 assignees View on GitHub
Component: test-framework
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

When using JerseyTest with JUnit 5 a null pointer exception gets thrown:

```
java.lang.NullPointerException
at org.glassfish.jersey.test.JerseyTest.target(JerseyTest.java:564)
at org.glassfish.jersey.test.JerseyTest.target(JerseyTest.java:578)
```

The issue seems to be that the setup() and tearDown() functions in the JerseyTest class are not called in JUnit 5 as they would be in JUnit 4. JUnit 5 uses the convention of @Before and @After annotations.

Here is my workaround, in the test class that extends JerseyTest add the following two methods:

```java
// do not name this setup()
@BeforeAll
public void before() throws Exception {
super.setUp();
}

// do not name this tearDown()
@AfterAll
public void after() throws Exception {
super.tearDown();
}

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.