基于python的接口自动化测试框架
Test部分基于yingoja开源的DemoApi优化修改而来
API部分将继续完善,提供基于C#,Go,Java,Python版本的Api服务程序,目的是为了学习接口测试的同学不需要去搭建其他语言的运行环境,顺便我也复习一下这几门语言的基础语法。
https://github.com/dwBurning/AutoApiTest.git
C#是我的第一语言,对比Go,Java,Python,还是觉得C#的语法,最好使,也最优雅,不要喷我,这只是个人观点。
这部分很简单就不做过多的介绍了,如果你的电脑上安装了.NetCore的环境,那么拉取代码后直接运行就行了,核心类PersonController提供满足restful接口规范的http服务,对Person资源执行增删改查。
using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace AutoApiTest.Controllers { /// <summary> /// 人事信息管理 /// </summary> [ApiController] [Route("api/[controller]")] public class PersonController : ControllerBase { static List<Person> peoples = new List<Person>(); /// <summary> /// 获取所有的人事信息 /// </summary> /// <returns></returns> [HttpGet] public OutPut<List<Person>> Get() { return new OutPut<List<Person>>() { Code = 0, Message = "获取成功", Data = peoples }; ; } /// <summary> /// 根据ID获取人事信息 /// </summary> /// <returns></returns> [HttpGet("{id}")] public OutPut<Person> Get(int id) { var p = peoples.Find(x => x.Id == id); if (p != null) { return new OutPut<Person>() { Code = 0, Message = "获取成功", Data = p }; } else { return new OutPut<Person>() { Code = -1, Message = "人事资料不存在" }; } } /// <summary> /// 根据ID删除人事信息 /// </summary> /// <param name="id"></param> [HttpDelete("{id}")] public OutPut<string> Delete(int id) { if (peoples.Remove(peoples.Find(x => x.Id == id))) { return new OutPut<string>() { Code = 0, Message = "删除成功" }; } return new OutPut<string>() { Code = -1, Message = "人事资料不存在" }; } /// <summary> /// 修改人事信息 /// </summary> /// <param name="person"></param> /// <returns></returns> [HttpPatch("{id}")] public OutPut<string> Patch(Person person) { var p = peoples.Find(x => x.Id == person.Id); if (p != null) { p.Name = person.Name; p.Age = person.Age; return new OutPut<string>() { Code = 0, Message = "修改成功" }; } else { return new OutPut<string>() { Code = -1, Message = "人事资料不存在" }; } } /// <summary> /// 新增人事资料 /// </summary> /// <param name="person"></param> /// <returns></returns> [HttpPost] public OutPut<string> Post(Person person) { var p = peoples.Find(x => x.Id == person.Id); if (p != null) { return new OutPut<string>() { Code = -1, Message = "人事资料已存在" }; } else { peoples.Add(person); return new OutPut<string>() { Code = 0, Message = "添加成功" }; } } } }