问题描述:

My task is to implement integration tests which have to use remote restful service. Thing is, that we don't want any test data put in real restful service.

In general we have:

Controller responsible for saving and loading data from RESTful:

 @RequestMapping(value="/user/save", method = RequestMethod.POST)

saveUserData(@RequestParam String data, @RequestParam String user){

// here is the logic to send the data to save

restfulClient.save(user, data);

}

@RequestMapping(value="/user/load", method = RequestMethod.POST)

loadUserData(@RequestParam String data , @RequestParam String user){

// here is the logic to load the data from restful service

return restfulClient.load(user, data);

}

RestfulClient just makes put and get requests to remote restful service to save and load user data.

2 Cucumber scenario:

 When user User is saving data some_data

Then user User sees saved data is some_data

3 Cucumber test:

@When("^user (.+) is saving data (.+)$")

public void whenSave(String userName, String data) throws Exception {

MockHttpServletRequestBuilder req = post("/user/save").contentType(APPLICATION_JSON_UTF8).content(data);

callUrl = getMockMvc().perform(req.session(userName));

}

@Then("^user (.+) sees saved data is (.+)$")

public void thenResponseAndDataAreCorrect(String userName, String data) throws Exception {

MockHttpServletRequestBuilder req = get("/user/load").content(data);

callUrl = getMockMvc().perform(req.session(req.session(userName));

callUrl.andExpect(status().isOk());

callUrl.andExpect(jsonPath("$.Records[*].data", hasItems(userName)));

}

Tests can be executed simultaneously in different threads so the user_id can be different for each test. In this case we need the possibility to write and to read the data for each id.

http://some.restful.service/{user_id}

Will be good to know some approach that we can use in case described above.

网友答案:

What kind of software project management are you using? E.g. You can use maven and you could launch the integration test. Click here for more help: http://clearqa.blogspot.com.es/2013/04/fun-with-cucumber-jvm-bdd.html

相关阅读:
Top