Spring Junit Test Drive for Controller Support

I have a controller that answers REST calls, I have various test cases for my other public methods.

I do not know how to write one for my controller:

@RequestMapping(value = "/api/frames", method = RequestMethod.GET) public List<Frame> getFrames( @RequestParam(value="frameLength", required=true) Double frameLength, @RequestParam(value="frameBreadth", required=true) Double frameBreadth, @RequestParam(value="mountThickness", required=true) Double mountThickness, @RequestParam(value="frameThickness", required=true) Double frameThickness){ List<Frame> tempFrames = new ArrayList<>(); List<FrameVariant> frameVariants = frameVariantService.getFrames( frameLength, frameBreadth, mountThickness, frameThickness); for (FrameVariant frameVariant : frameVariants) { tempFrames.add(new Frame(frameVariant)); } return tempFrames; } 

I do not know how to write a test case for this controller method.

+5
source share
2 answers

Take a look at MockMvc . This is part of the Spring test module.

These tutorials are pretty detailed and detailed, so you should immediately understand how to test Spring MVC controllers.

+8
source

This article provides a good introduction to testing REST controllers with MockMvc. Sample code for this post is available on Github.

0
source

Source: https://habr.com/ru/post/1204182/


All Articles