jmeter 断言
设置 预期结果 接口返回码为500

结果


设置返回结果 响应文本 包含 失败

结果



对一个接口做判断既需要判断返回码 又需要判断返回的文本
准备环境使用springboot 搭建一个post请求‘

代码
package com.example.demo2.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import java.util.HashMap; import java.util.Map; @RestController public class HelloController { @RequestMapping(value="/hello",method = RequestMethod.GET) public @ResponseBody Object hello(){ //调用业务 System.out.println("get request"); return "hello,world"; } @RequestMapping(value="/login",method = RequestMethod.POST) public@ResponseBody Object login(String name,String pwd){ //调用业务 System.out.println("post request"); Map<String ,Object> map = new HashMap<>(); //表单形式 同时发送pwd=123 name=jack时 返回status 0 if("123".equals(pwd)&&"jack".equals(name)){ map.put("status",0); }else { // 否则 返回 status -1 map.put("status",-1); } return map; } }
在jmeter中设置post请求

实际效果’

浙公网安备 33010602011771号