gpt4 book ai didi

Play 框架中的 java.lang.NoSuchMethodError Rest Assured 异常

转载 作者:行者123 更新时间:2023-12-02 11:45:35 24 4
gpt4 key购买 nike

嗨,我正在使用 play 框架 2.4.3 和 scala 版本 2.11我正在使用放心的 scala 支持来测试路由,但我得到了

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

经过研究,我发现 Junit 导致了放心的 hamcrest matcher 中的问题 NoSuchMethodError with Hamcrest 1.3 & JUnit 4.11因为我使用的是 play 框架,所以我认为它默认带有 Junit,也许这就是导致问题的原因这是代码

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"))
}
}

}

这里是build.sbt文件内容

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")

这是异常日志

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)

请帮助解决导致异常的原因

最佳答案

明确添加对 Hamcrest 的依赖

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

关于Play 框架中的 java.lang.NoSuchMethodError Rest Assured 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48225632/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com