I am newbie in writing unit test cases.
Things that I have to follow:
- I have to work using Mockito tool. And I read it is very useful tool.
- I have written services in spring mvc. It is having controller, business layer, pojos, dao's.
- I have both GET and POST services.
- For beginning I want to start with POST service.
- Response will be always in JSON and for POST Service request will be in JSON.
- Which steps I should follow to write good unit test cases.
- Please suggest some good tutorials.
Snippet of controller class:
@Controller
public class Controller
{
@Autowired ManagerClass manager;
@RequestMapping(value = "/app/data/send", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<ResponseData> DataInquiry(@RequestBody RequestData requestData,
@RequestHeader(value = Constants.HEADER_TRANS_ID, required = false) String transactionId) {
ResponseData responseData = new ResponseData();
try {
responseData = manager.retrieveData(requestData);
} catch (Exception e) {
logger.error("Exception " + e);
}
HttpHeaders headers = new HttpHeaders();
headers.add(Constants.HEADER_TRANS_ID, transactionId);
return new ResponseEntity<ResponseData>(responseData, headers, HttpStatus.OK);
}
}
public class ManagerClass
{
@Override
public ResponseData retrieveData(RequestData requestData) {
Here Call will be made to dao layer by passing some parameters from requestdata in the method and in return response will be sent back to controller
}
}
Aucun commentaire:
Enregistrer un commentaire