2
//1) Request
//Given
String req = new ObjectMapper().writeValueAsString(new Request("2016-11-15"));
//set HttpHeaders
//set HttpEntity
// When
ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);

Is there a convenient way of unit testing multiple REST API requests? I would like to create a bunch of requests to submit to a queue which will then be processed. The request are to have different HttpHeaders and different ReportRequestBody.

I have done single request unit testing and are able to capture statuses using ResponseEntity.

Can anyone point me to some examples or documentation on best practices. I am a beginner and I am not sure where to start with multiple requests.

nick zoum
  • 7,216
  • 7
  • 36
  • 80
M06H
  • 1,675
  • 3
  • 36
  • 76
  • 2
    I don't know if this is the right approach. If you're testing multiple REST requests at once, where is the "unit" that you're trying to test? This looks more like you wanted some kind of integration tests. There are APIs like [Mockito](http://site.mockito.org/) and [Spring MockMVC](http://docs.spring.io/spring-security/site/docs/current/reference/html/test-mockmvc.html) to do that kind of testing. – QBrute Nov 15 '16 at 13:30
  • @Qbrute I mean to say integration test yes. – M06H Nov 15 '16 at 13:46

2 Answers2

1

For testing requests and responses in DjangoRest you can use following tools or ways....

  • You can use print statement to see what is being printed and then you can interpret print results accordingly.
  • You can use Debugger of any IDE such as PyCharm.
  • You can use Postman to test your API as it gives you whole idea of the responses you are getting.
  • For more information on requests you can visit here
Amrit
  • 2,115
  • 1
  • 21
  • 41
0

Yes I would certainly say this is more of an integration/load test scenario. You may want to look into using Jmeter with Junit tests. You can use its JUnit Request Sampler. Here was a post on stackoverflow to a different question, but it provides a link to a helpful article. The post was Spring load testing . Here is also a link to the article directly https://www.blazemeter.com/blog/how-use-junit-jmeter. This should get you heading in the right direction.

Community
  • 1
  • 1
M. Rizzo
  • 1,611
  • 12
  • 24