我已经发现了三个与同一问题有关的问题,但不知怎的,他们并没有完全解决我的问题.
Hamcrest 1.3和JUnit 4.11的NoSuchMethodError
当我在eclipse中运行测试时,NoSuchMethodError:org.hamcrest.Matchers.hasXPath
在IntelliJ 10.5中运行测试时获取"NoSuchMethodError:org.hamcrest.Matcher.describeMismatch"
单元测试工作正常但是在RestAssured Tests失败时的集成测试期间:
expect().
statusCode(Status.CREATED.getStatusCode()).log().all().
when().
post("/projects").
then().
body("directory", Matchers.anything()).body("files", Matchers.empty());
Run Code Online (Sandbox Code Playgroud)
正如其他三个相关问题已经说过的那样,似乎存在一些与TestNG/JUnit和Hamcrest和/或Mockito相互冲突的问题,所以我尝试了各种各样的exlus和其他包含所述工件的内容,但遗憾的是无济于事.虽然有效但不使用RestAssured中的log().all(),它必须是问题的根源.因此,这将工作:
expect().
statusCode(Status.CREATED.getStatusCode()).
when().
post("/projects").
then().
body("directory", Matchers.anything()).body("files", Matchers.empty());
Run Code Online (Sandbox Code Playgroud)
我希望能够在esting的同时看到REST调用的实际输出,所以我很高兴对此有任何想法.谢谢!
这是控制台输出
java.lang.NoSuchMethodError: org.hamcrest.core.IsInstanceOf.any(Ljava/lang/Class;)Lorg/hamcrest/Matcher;
at org.hamcrest.Matchers.any(Matchers.java:371)
at com.jayway.restassured.filter.log.ResponseLoggingFilter.<init>(ResponseLoggingFilter.java:94)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:57)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:198)
at com.jayway.restassured.internal.ResponseLogSpecificationImpl.logWith(ResponseLogSpecificationImpl.groovy:85)
at com.jayway.restassured.internal.ResponseLogSpecificationImpl.this$3$logWith(ResponseLogSpecificationImpl.groovy)
at com.jayway.restassured.internal.ResponseLogSpecificationImpl$this$3$logWith.callCurrent(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:145)
at com.jayway.restassured.internal.ResponseLogSpecificationImpl.all(ResponseLogSpecificationImpl.groovy:45)
at com.jayway.restassured.internal.ResponseLogSpecificationImpl.all(ResponseLogSpecificationImpl.groovy)
at com.jayway.restassured.specification.LogSpecification$all.callCurrent(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141) …Run Code Online (Sandbox Code Playgroud)