Postman interface test tool usage guide
What is the Postman interface testing tool
Postman is an interface debugging and testing tool that supports THE HTTP protocol. Its main features are powerful, easy to use, and easy to use.
Postman is one of our preferred tools for both developers debugging interfaces and testers testing them.
Download and install Postman
Postman won’t support browser versions after 2018, so to use postman, you must download the client and install it. Here’s an example of how to install postman on Windows.
1. Postman installation procedure
(1) Visit the official website of Postman and download
Visit www.getpostman.com/
(2) Enter the download page and download the corresponding version according to your computer
(3) Installation
Right click to install postman-win64-7.11.0-setup.exe
(4) Modify the theme
Choose File=> Setting => Themes to modify the theme
(5) Modify the font
Select File=>setting=>General to modify the font
2. Create project interface tests
(1) Create an interface test set
(2) After the vm is created successfully
Create a request interface
- Right-click ems_RestFul and choose Add Request
- Add the interface name and description
- After a successful creation
The use of Postman
1. Interface test related library table
CREATE TABLE `t_emp` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`salary` double NOT NULL,
`age` int NOT NULL.PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 15 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of t_emp
-- ----------------------------
INSERT INTO `t_emp` VALUES (2.'Yang Fujun'.9000.19);
INSERT INTO `t_emp` VALUES (8.'Wang Heng Jie'.12000.21);
INSERT INTO `t_emp` VALUES (12.'Deng Zhengwu'.20000.22);
INSERT INTO `t_emp` VALUES (13.'The Lord of Zhou'.18000.23);
INSERT INTO `t_emp` VALUES (14.'Wu Hongxu'.2000.23);
Copy the code
2. Controller layer of POatman test interface meets RestFul style
@RestController
@RequestMapping("tEmp")
public class TEmpController {
/**
* 服务对象
*/
@Resource
private TEmpService tEmpService;
/** ** *@paramTEmp Filter criteria *@paramPageRequest page object *@returnQuery result */
@GetMapping
public ResponseEntity<Page<TEmp>> queryByPage(TEmp tEmp, PageRequest pageRequest) {
return ResponseEntity.ok(this.tEmpService.queryByPage(tEmp, pageRequest));
}
/** * Query single data ** by primary key@param* id primary key@returnSingle data */
@GetMapping("{id}")
public ResponseEntity<TEmp> queryById(@PathVariable("id") Integer id) {
return ResponseEntity.ok(this.tEmpService.queryById(id));
}
/** * Add data **@paramTEmp entity *@returnNew result */
@PostMapping
public ResponseEntity<TEmp> add(TEmp tEmp) {
return ResponseEntity.ok(this.tEmpService.insert(tEmp));
}
/** * edit data **@paramTEmp entity *@returnEdit the result */
@PutMapping
public ResponseEntity<TEmp> edit(TEmp tEmp) {
return ResponseEntity.ok(this.tEmpService.update(tEmp));
}
/** * delete data **@param* id primary key@returnCheck whether the deletion succeeded */
@DeleteMapping
public ResponseEntity<Boolean> deleteById(Integer id) {
return ResponseEntity.ok(this.tEmpService.deleteById(id)); }}Copy the code
3. Get interface test
- Run the id=8 command to query Wang Hengjie
4. Configure the port environment
- All of our requests so far are port 8080, so you can set up the environment directly
- Click Add Environment
- Add the environment
- Add environment name
- Click on the key environment to add it
- Set the basic access path to http://localhost:8080
- use
{{baseUrl}}
Use the configured environment variables
5. Realize the deletion function
- Copying an interface
- Delete zhou Xuanjun where id=13
- Delete using postman
/** * Query single data ** by primary key@param* id primary key@returnSingle data */
@GetMapping("{id}")
public ResponseEntity<TEmp> queryById(@PathVariable("id") Integer id) {
return ResponseEntity.ok(this.tEmpService.queryById(id));
}
Copy the code
- After successful deletion
- Console print statement
6. Add functions
/** * Add data **@paramTEmp entity *@returnNew result */
@PostMapping
public ResponseEntity<TEmp> add(TEmp tEmp) {
return ResponseEntity.ok(this.tEmpService.insert(tEmp));
}
Copy the code
- Add employees
- After successful addition
7. Realize the function of uploading files
- Console statement
@PostMapping("/file")
public void savePhoto(MultipartFile photo) {
log.debug("File name" + photo.getOriginalFilename());
log.debug("File size" + photo.getSize());
log.debug("File Type" + photo.getContentType());
}
Copy the code
- Select form-Data for the test interface
- Console result after successful test
8. Implement modification test
- Modify the data before Liu Jianping
- Control layer
/** * edit data **@paramTEmp entity *@returnEdit the result */
@PutMapping
public ResponseEntity<TEmp> edit(@RequestBody TEmp tEmp) {
return ResponseEntity.ok(this.tEmpService.update(tEmp));
}
Copy the code
- Select Put=> click Body=> Click RAW => Select JSON
- Result after modification