泽西测试框架。测试容器为空

问题描述 投票:0回答:1

我有以下测试类,测试一个简单的 "/helloWorld" 中实现的端点。jax-rs. 我把这个文件作为EAR文件运行在一个 JBOSS EAP 服务器本地。

public class HelloWorldTest extends JerseyTest {


    @Override
    protected Application configure() {
        return new ResourceConfig(HelloWorldEndpoint.class);
    }

    @Override
    public TestContainerFactory getTestContainerFactory() {
        return new GrizzlyWebTestContainerFactory();
    }

    @Test
    public void shouldGetApplyStreams() {

        Response response = target("/helloWorld").request()
                .get();

        assertEquals("Http Response should be 200: ", Response.Status.OK.getStatusCode(), response.getStatus());
    }
}

当我运行测试时,我得到了以下结果。

java.lang.NullPointerException
    at org.glassfish.jersey.test.JerseyTest.target(JerseyTest.java:565)
    at org.glassfish.jersey.test.JerseyTest.target(JerseyTest.java:579)
    at com.hrlogix.ats.http.unsecured.ApplyFlowEndpointTest.shouldGetApplyStreams(HelloWorldEndpointTest.java:33)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    at org.testng.TestRunner.privateRun(TestRunner.java:648)
    at org.testng.TestRunner.run(TestRunner.java:505)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
    at org.testng.SuiteRunner.run(SuiteRunner.java:364)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
    at org.testng.TestNG.runSuites(TestNG.java:1049)
    at org.testng.TestNG.run(TestNG.java:1017)
    at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
    at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:110)
java jboss testng jax-rs jersey-test-framework
1个回答
0
投票

JerseyTest目前与JUnit 5不兼容。

https:/github.comjerseyjerseyissues3662

从他们的工作方法来看,增加

@TestInstance(Lifecycle.PER_CLASS)

到你的类,以及这两个方法。

// 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();
}
© www.soinside.com 2019 - 2024. All rights reserved.