I was developing the RESTful web service with springmvc4 and spring data jpa.Well, I have about 100+ apis for frontend to pull data.What I am want to do is how to test all of my apis automatically with random data. The apis look like:
@RestController
@Api(tags = "index")
@RequestMapping("/index")
public class IndexController {
@Autowired
private IndexService indexService;
@RequestMapping(value = "/data", method = RequestMethod.GET)
@ApiOperation(value="today's data",notes="today's data",consumes="application/json",produces="application/json")
public Object getTodayData() {
return indexService.getTodayData();
}
@RequestMapping(value = "/chartData", method = RequestMethod.GET)
@ApiOperation(value="charts data",notes="charts data",consumes="application/json",produces="application/json")
public Object getLast7Data() {
return indexService.getLast7Data();
}
}
if I test it with postman one by one,it was waste a lot of time.When we developping,we should make sure the service is ok by ourselves. I have got a solution but which is not satisfied me well. here are my solution:
Scaned the controller of the specified package,then use reflection get the annotation of the class,which could get the value of @RequestMapping("/index").
Iterate through the method of the class and get the method's annotation the same way,and get the full url.
- Create random data for request, execute request and log the response. Could anyone provide a solution for this, very appreciate for your help.