用于控制器其余服务的Spring Junit测试用例 [英] Spring Junit test case for controller rest service

查看:70
本文介绍了用于控制器其余服务的Spring Junit测试用例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制器来响应REST调用,我的其他公共方法也有各种测试用例.

I have a controller which responds to 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 have no clue how to write a test case for this controller method.

推荐答案

看看

Take a look at MockMvc. It's part of Spring Test module.

这些教程具有很强的描述性,并且涉及到细节,因此您应该立即了解如何测试Spring MVC控制器.

These tutorials are pretty descriptive and going into details so you should get idea straight away how to test Spring MVC controllers.

这篇关于用于控制器其余服务的Spring Junit测试用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆