接口测试工具——Postman测试工具 & Swagger接口测试+SpringBoot整合 & JMeter高并发测试工具

目录

IDEA简单测试


Postman测试工具


post请求

头部携带token

类型选择JSON

接口测试工具swagger

https://apifox.com/

swagger2,较多

swagger3,

Knife4j

Knife4j的前身是swagger-bootstrap=ui,前身swagger--bootstrap-ui是一个纯swagger--ui的ui皮肤项目

https://doc.xiaominfo.com/docs/quick-start

1.引入依赖

xml 复制代码
        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>knife4j-openapi2-spring-boot-starter</artifactId>
            <version>4.1.0</version>
        </dependency>

底层就是swagger

2.配置

yml 复制代码
knife4j:
  enable: true

3.常用注解

java 复制代码
import io.swagger.annotations.Api;
序号 注解 作用
1 @Api(tags = "图书的api接口类") 左侧名字
2 @ApiOperation("findPage方法测试") get方法名字
3 @ApiImplicitParam(name = "findByPage",value = "分页查询",required = true) 参数相关
4 @ApiModel("DTO返回数据") 写在HttpResp实体类上
5 @ApiModelProperty("time") 写在HttpResp类属性上

BookController.java文件

java 复制代码
package com.tinaju.bm.controller;

import com.tinaju.bm.dto.HttpResp;
import com.tinaju.bm.dto.ResultCode;
import com.tinaju.bm.entity.Book;
import com.tinaju.bm.service.IBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@Api(tags = "图书的api接口类")
@RestController
@RequestMapping("/api/book")
public class BookController {
    @Autowired
    private IBookService bookService;

    @ApiOperation("findPage方法测试")
    @ApiImplicitParam(name = "findByPage",value = "分页查询",required = true)
    @GetMapping("/findByPage")
    public HttpResp findByPage(int currentPage){
        List<Book> bookList = bookService.findByPage(currentPage, 5);
        return HttpResp.results(ResultCode.BOOK_SUCCESS,new Date(),bookList);
    }
}

HttpResp.java返回给前端的实体类

java 复制代码
package com.tinaju.bm.dto;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import java.io.Serializable;
import java.util.Date;

/**
 * 返回给前端的响应
 * @param <T>
 */
@ApiModel("DTO返回数据")
@Getter@Setter
@ToString
public class HttpResp<T> implements Serializable {

    private ResultCode resultCode;
    @ApiModelProperty("time")
    private Date time;
    @ApiModelProperty("results")
    private T results;

    private HttpResp(){}

    public static <T> HttpResp<T> results(ResultCode resultCode,Date time,T results){ // java泛型的写法
        HttpResp httpResp = new HttpResp();
        httpResp.setResultCode(resultCode);
        httpResp.setTime(time);
        httpResp.setResults(results);
        return httpResp;
    }
}

4.接口测试

ip: 端口/doc.html

JMeter

什么是JMeter?

Apache JMeter™

The Apache JMeter™ application is open source software, a 100% pure Java application designed to load test functional behavior and measure performance(接口性能),It was originally designed for testing Web Applications but has since expanded to other test functions.

JMeter安装配置

1.官网下载

2.下载后解压

3.汉语设置

JMeter的使用方法

1.新建线程组

2.设置参数

3.添加取样器

4.设置参数:协议,ip,端口,请求方式,路径

5.添加查看结果树

6.启动+查看结果

相关推荐
工业甲酰苯胺25 分钟前
Spring Boot 整合 MyBatis 的详细步骤(两种方式)
spring boot·后端·mybatis
bjzhang752 小时前
SpringBoot开发——集成Tess4j实现OCR图像文字识别
spring boot·ocr·tess4j
flying jiang2 小时前
Spring Boot 入门面试五道题
spring boot
小菜yh2 小时前
关于Redis
java·数据库·spring boot·redis·spring·缓存
爱上语文4 小时前
Springboot的三层架构
java·开发语言·spring boot·后端·spring
荆州克莱4 小时前
springcloud整合nacos、sentinal、springcloud-gateway,springboot security、oauth2总结
spring boot·spring·spring cloud·css3·技术
serve the people4 小时前
springboot 单独新建一个文件实时写数据,当文件大于100M时按照日期时间做文件名进行归档
java·spring boot·后端
罗政9 小时前
[附源码]超简洁个人博客网站搭建+SpringBoot+Vue前后端分离
vue.js·spring boot·后端
Java小白笔记12 小时前
关于使用Mybatis-Plus 自动填充功能失效问题
spring boot·后端·mybatis
小哇66612 小时前
Spring Boot,在应用程序启动后执行某些 SQL 语句
数据库·spring boot·sql