Jersey测试框架的ClassNotFoundException

时间:2017-05-06 08:36:18

标签: unit-testing jersey jax-rs jersey-test-framework

我试图使用Jersey Test Framework并且我对它不满意。

java.lang.RuntimeException: java.lang.ClassNotFoundException
        at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:46)
        at javax.ws.rs.client.ClientBuilder.newClient(ClientBuilder.java:57)
        at org.glassfish.jersey.test.JerseyTest.getClient(JerseyTest.java:691)
        at org.glassfish.jersey.test.JerseyTest.setUp(JerseyTest.java:614)
        at org.glassfish.jersey.test.JerseyTestNg$ContainerPerClassTest.setUp(JerseyTestNg.java:181)
        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:108)
        at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523)
        at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224)
        at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146)
        at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:166)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:105)
        at org.testng.TestRunner.privateRun(TestRunner.java:744)
        at org.testng.TestRunner.run(TestRunner.java:602)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
        at org.testng.SuiteRunner.run(SuiteRunner.java:289)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
        at org.testng.TestNG.runSuites(TestNG.java:1144)
        at org.testng.TestNG.run(TestNG.java:1115)
        at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:135)
        at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:193)
        at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:94)
        at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:146)
        at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:386)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:323)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:143)
Caused by: java.lang.ClassNotFoundException
        at javax.ws.rs.client.ClientFinder.newInstance(ClientFinder.java:116)
        at javax.ws.rs.client.ClientFinder.find(ClientFinder.java:92)
        at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:40)
        ... 33 more
Caused by: java.lang.InstantiationException
        at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at java.lang.Class.newInstance(Class.java:442)
        at javax.ws.rs.client.ClientFinder.newInstance(ClientFinder.java:112)
        ... 35 more

[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR]   ProductsResourceTest>JerseyTestNg$ContainerPerClassTest.setUp:181->JerseyTest.setUp:614->JerseyTest.getClient:691 ? Runtime
[INFO]
[ERROR] Tests run: 3, Failures: 1, Errors: 0, Skipped: 2
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.603 s
[INFO] Finished at: 2017-05-06T17:24:35+09:00
[INFO] Final Memory: 18M/279M
[INFO] ------------------------------------------------------------------------

javax.ws.rs.client.ClientFinter来自哪里?

这是我的依赖。 (来自:effective-pom)

  <dependencies>
    <dependency>
      <groupId>org.apache.tomee</groupId>
      <artifactId>openejb-core</artifactId>
      <version>7.0.3</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.core</groupId>
      <artifactId>jersey-client</artifactId>
      <version>2.26-b03</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.test-framework.providers</groupId>
      <artifactId>jersey-test-framework-provider-jdk-http</artifactId>
      <version>2.26-b03</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>javax</groupId>
      <artifactId>javaee-api</artifactId>
      <version>7.0</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>

0 个答案:

没有答案