2015-08-07 2 views
0

Я использую RestAssuredMockMvc для модульных контроллеров весеннего mvc. Это мой код:Нет такой ошибки метода при использовании RestAssuredMockMvc

import com.xyz.api.controller.UserController; 
import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc; 
import org.junit.Before; 
import org.junit.Test; 

import javax.servlet.http.HttpServletResponse; 

import static org.hamcrest.Matchers.equalTo; 

public class UserControllerRest { 

    private String userName = "[email protected]"; 
    private String expectedResult = "Hello " + userName; 

    @Before 
    public void initialize() { 
     RestAssuredMockMvc.standaloneSetup(new UserController()); 
    } 

    @Test 
    public void checkResponseAndBody() throws Exception { 
     RestAssuredMockMvc.given().param("userName", userName).when().get("/users").print(); 
     RestAssuredMockMvc.given().param("userName", userName).when().get("/users").then().assertThat().statusCode(200).and().body(equalTo(expectedResult)); 
    } 
} 

Первое заявление в checkResponseAndBody() принтах: Hello [email protected] Но вторая строка дает следующее сообщение об ошибке:

java.lang.NoSuchMethodError: com.jayway.restassured.internal.ValidatableResponseOptionsImpl.<init>(Ljava/lang/String;Lcom/jayway/restassured/internal/ResponseParserRegistrar;Lcom/jayway/restassured/config/RestAssuredConfig;Lcom/jayway/restassured/response/Response;Lcom/jayway/restassured/response/ExtractableResponse;)V 
    at com.jayway.restassured.module.mockmvc.internal.ValidatableMockMvcResponseImpl.<init>(ValidatableMockMvcResponseImpl.java:37) 
    at com.jayway.restassured.module.mockmvc.internal.MockMvcRestAssuredResponseImpl.then(MockMvcRestAssuredResponseImpl.java:36) 
    at com.giddh.api.restassured.UserControllerRest.checkResponseAndBody(UserControllerRest.java:25) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) 
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) 
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137) 
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78) 
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212) 
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140) 

Я видел примеры и даже пытался использовать те же но все же ошибка сохраняется. Как я могу это решить?

ответ

0

Возможно, вы не добавили все зависимости к вашему пути к классам. Как указано на странице download, вам также необходимо загрузить и поместить содержимое rest-assured-2.5.0-dist.zip в свой путь к классам.

Если вы используете Maven оно должно быть достаточно, чтобы просто зависеть от spring-mock-mvc модуля:

<dependency> 
     <groupId>com.jayway.restassured</groupId> 
     <artifactId>spring-mock-mvc</artifactId> 
     <version>${rest-assured.version}</version> 
     <scope>test</scope> 
</dependency> 

Или Gradle:

testCompile "com.jayway.restassured:spring-mock-mvc:${rest-assured.version}" 
Смежные вопросы