简体   繁体   中英

java.lang.NoSuchMethodError Rest Assured exception in play framework

Hi I am using play framework 2.4.3 and scala version 2.11 I am using rest assured scala support for testing routes but i am getting

java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V

after researching I found out that Junit causes the problem in rest assured hamcrest matcher NoSuchMethodError with Hamcrest 1.3 & JUnit 4.11 as I am using play framework I think it comes with Junit by default maybe this was causing the problem here is the code

import io.restassured.RestAssured._
import io.restassured.RestAssured.when
import io.restassured.module.scala.RestAssuredSupport.AddThenToResponse
import io.restassured.matcher.RestAssuredMatchers._
import org.hamcrest.Matchers._
import org.scalatest._
import org.scalatest.FunSpec
import play.api.libs.json._

describe("user signed up")
  {
    it("user inserted to db after signup")
    {
      val json: JsValue = JsObject(Seq(
       "firstName" -> JsString("alice"),
       "lastName" -> JsString("bob"),
       "email" -> JsString("example@gmail.com"),
       "secondryEmail" -> JsString("example1@gmail.com"),
       "password" -> JsString("a@s**dasda_sds5")
    ))
      given()
      .port(9000)
      .contentType("application/json") 
      .body(json.toString())
     .when()
      .post("/direct-user/signup-processing")
     .Then()
       .statusCode(200)
       .body("status", equalTo(200)
           ,"msg", equalTo("Signup Successful"))
    }
  }

}

here is build.sbt file contents

libraryDependencies ++= Seq(filters, 
                "io.rest-assured" % "scala-support" % "3.0.6",
                "org.scalatest" %% "scalatest" % "2.2.6" % "test"withSources() withJavadoc(),
                "org.scalatestplus" %% "play" % "1.4.0-M3" % "test",
                "com.esotericsoftware.kryo" % "kryo" % "2.10",
                "org.mongodb" %% "casbah" % "2.8.0",
                "org.slf4j" % "slf4j-api" % "1.6.4",
                "org.elasticsearch" % "elasticsearch" % "1.6.0",
                "com.typesafe.akka" %% "akka-actor" % "2.3.6",
                "com.typesafe.akka" % "akka-testkit_2.11" % "2.3.6",
                "ch.qos.logback" % "logback-core" % "1.0.9",
                "com.github.nscala-time" %% "nscala-time" % "2.0.0",
                "com.hazelcast" % "hazelcast" % "3.5",
                "com.hazelcast" % "hazelcast-client" % "3.5",
                "com.twitter" % "chill-bijection_2.11" % "0.7.0",
                "com.github.slugify" % "slugify" % "2.1.3" ,
                "org.mindrot" % "jbcrypt" % "0.3m",
                "org.codehaus.groovy" % "groovy-all" % "2.4.0",
                "org.apache.lucene" % "lucene-expressions" % "4.10.4",
                "com.restfb" % "restfb" % "1.19.0",
                "org.twitter4j" % "twitter4j-core" % "4.0.0",
                "org.scribe" % "scribe" % "1.3.5",
                "com.google.code.gson" % "gson" % "2.6.2",
                "com.google.oauth-client" % "google-oauth-client" % "1.20.0",
                "com.google.api.client" % "google-api-client-auth-oauth2" % "1.2.0-alpha",
                "com.google.api-client" % "google-api-client" % "1.20.0",
                "com.google.http-client" % "google-http-client-jackson" % "1.20.0",
                "com.google.apis" % "google-api-services-oauth2" % "v2-rev120-1.20.0",
                "com.google.oauth-client" % "google-oauth-client-appengine" % "1.20.0",
                "com.google.oauth-client" % "google-oauth-client-java6" % "1.20.0",
                "com.google.oauth-client" % "google-oauth-client-jetty" % "1.20.0",
                "com.google.oauth-client" % "google-oauth-client-servlet" % "1.20.0",
                "com.google.apis" % "google-api-services-calendar" % "v3-rev120-1.19.1",
                "com.google.inject" % "guice" % "3.0")

and here is the exception log

DirectUserSignUpTest:
[info] user signed up
[info] Exception encountered when attempting to run a suite with class name: endtoendtesting.directusertests.DirectUserSignUpTest *** ABORTED ***
[info]   java.lang.NoSuchMethodError: org.hamcrest.Matcher.describeMismatch(Ljava/lang/Object;Lorg/hamcrest/Description;)V
[info]   at io.restassured.internal.util.MatcherErrorMessageBuilder.buildError(MatcherErrorMessageBuilder.java:19)
[info]   at io.restassured.internal.util.MatcherErrorMessageBuilder$buildError.call(Unknown Source)
[info]   at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
[info]   at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
[info]   at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
[info]   at io.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure.validateStatusCodeAndStatusLine(ResponseSpecificationImpl.groovy:536)
[info]   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[info]   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[info]   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[info]   at java.lang.reflect.Method.invoke(Method.java:498)

please help what is causing the exception

Add the dependency to Hamcrest explicitly

libraryDependencies ++= Seq(filters, 
    "org.hamcrest" % "hamcrest-core" % "1.3",
    "org.hamcrest" % "hamcrest-library" % "1.3",
    ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM