JerseyTest and JUnit throws NullPointerException
Your methods seem to override some important initialization made in parent JerseyTest
.
Try to name them differently. E.g.:
@Before
public void setUpChild() { }
@After
public void tearDownChild() { }
I came here because I was using JUnit 5 and it seems that it wasn't seeing the @Before and @After annotations on the JerseyTest setup/tearDown methods. I had to override them and use the new JUnit 5 annotations
public class MyResourceTest extends JerseyTest {
@BeforeEach
@Override
public void setUp() throws Exception {
super.setUp();
}
@AfterEach
@Override
public void tearDown() throws Exception {
super.tearDown();
}
@Override
protected Application configure() {
return new ResourceConfig(MyResource.class);
}
@Test
public void SHOULD_RETURN_BAD_REQUEST() throws IOException {
System.out.println(target("myPath"));
assertEquals(1, 1);
}
}