shell脚本写的班级管理系统测试用例

简介: shell脚本写的班级管理系统测试用例

假设我们要测试一个简单的班级管理系统,其中包括学生的姓名、年龄、成绩三个属性。下面是一个简单的学生信息增删改查的操作示例:
首先,我们需要先初始化班级和学生的信息:

# 初始化班级信息
init_classroom() {
     
    curl -X POST -d '{"name":"class1"}' http://localhost:8080/classroom 
}

# 初始化学生信息
init_student() {
   
    for i in {
   1..3}; do
        echo "{\"name\":\"student${i}\",\"age\":$((i+10)),\"score\":$((i*50))}" | \
        curl -X POST -H "Content-Type: application/json" -d @- http://localhost:8080/student
    done
}

接下来,我们可以写几个简单的测试用例:

  • 创建一个新班级:
    test_add_classroom() {
         
    local classroom_id=$(curl -X POST -d "{\"name\":\"class2\"}" http://localhost:8080/classroom | jq -r '.id')
    assertEquals "class2" "$(curl -X GET "http://localhost:8080/classroom/${classroom_id}/info" | jq -r '.name')"
    }
    
  • 删除一个班级:
    test_remove_classroom() {
         
    local classroom_id=$(curl -X POST -d "{\"name\":\"class3\"}" http://localhost:8080/classroom | jq -r '.id')
    assertEquals "200" "$(curl -X DELETE "http://localhost:8080/classroom/${classroom_id}" | jq -r '.code')"
    }
    
  • 更新一个班级:

    test_update_classroom() {
         
    local classroom_id=$(curl -X POST -d "{\"name\":\"class4\"}" http://localhost:8080/classroom | jq -r '.id')
    assertEquals "200" "$(curl -X PUT -d "{
         \"name\":\"new_name\"}" "http://localhost:8080/classroom/${classroom_id}" | jq -r '.code')"
    
    assertEquals "new_name" "$(curl -X GET "http://localhost:8080/classroom/${classroom_id}/info" | jq -r '.name')"
    }
    
  • 查询学生信息:
    test_query_students() {
         
    local student_ids=$(curl -X GET "http://localhost:8080/students" | jq -r '.[] | .id')
    for student_id in $student_ids; do
        assertEquals "student$i" "$(curl -X GET "http://localhost:8080/student/${student_id}/info" | jq -r '.name')"
    done
    }
    
  • 添加一个学生:
    test_add_student() {
         
    local student_id=$(curl -X POST -d "{\"name\":\"student4\",\"age\":40,\"score\":200}" http://localhost:8080/student | jq -r '.id')
    assertEquals "200" "$(curl -X GET "http://localhost:8080/student/${student_id}/info" | jq -r '.code')"
    assertEquals "student4" "$(curl -X GET "http://localhost:8080/student/${student_id}/info" | jq -r '.name')"
    }
    
  • 修改一个学生:

    test_update_student() {
         
    local student_id=$(curl -X POST -d "{\"name\":\"student5\",\"age\":50,\"score\":250}" http://localhost:8080/student | jq -r '.id')
    assertEquals "200" "$(curl -X PUT -d "{
         \"name\":\"new_name\"}" "http://localhost:8080/student/${student_id}" | jq -r '.code')"
    
    assertEquals "new_name" "$(curl -X GET "http://localhost:8080/student/${student_id}/info" | jq -r '.name')"
    }
    
  • 删除一个学生:
    test_remove_student() {
         
    local student_id=$(curl -X POST -d "{\"name\":\"student6\",\"age\":60,\"score\":300}" http://localhost:8080/student | jq -r '.id')
    assertEquals "200" "$(curl -X DELETE "http://localhost:8080/student/${student_id}" | jq -r '.code')"
    }
    

最后,我们可以定义一个函数来运行所有的测试用例:

run_test() {
   
    init_classroom
    init_student
    test_add_classroom
    test_remove_classroom
    test_update_classroom
    test_query_students
    test_add_student
    test_update_
相关文章
|
22天前
|
测试技术 Linux
VPS一键测试脚本,无痕体验+自动导出,服务器测试更轻松
NodeQuality 是一款整合 Yabs、IPQuality、NetQuality 等主流 VPS 测试脚本的全能工具,支持一键测试硬件性能、IP属性、网络质量,并新增分享与导出功能。其“无痕测试”设计不安装依赖、不留残留,兼容性强;测试结果自动排版、截图并生成分享链接,极大提升效率。适合需要全面、快速、干净测试 VPS 的用户,是运维和测评的高效利器。
84 3
|
15天前
|
存储 测试技术 API
数据驱动开发软件测试脚本
今天刚提交了我的新作《带着ChatGPT玩转软件开发》给出版社,在写作期间跟着ChatGPT学到许多新知识。下面分享数据驱动开发软件测试脚本。
20 0
|
6月前
|
关系型数据库 MySQL Shell
MySQL 备份 Shell 脚本:支持远程同步与阿里云 OSS 备份
一款自动化 MySQL 备份 Shell 脚本,支持本地存储、远程服务器同步(SSH+rsync)、阿里云 OSS 备份,并自动清理过期备份。适用于数据库管理员和开发者,帮助确保数据安全。
|
2月前
|
Web App开发 JavaScript 测试技术
Playwright 极速入门:1 小时搞定环境搭建与首个测试脚本
本文带你1小时快速入门Playwright,完成环境搭建并编写首个测试脚本。Playwright是微软推出的现代化Web自动化测试工具,支持Chromium、Firefox和WebKit三大浏览器引擎,具备跨平台、多语言(Python/JS/Java/C#)特性。其核心优势包括:智能自动等待机制减少失败率、内置录制工具实时生成脚本、多语言灵活选择,以及真移动端设备模拟能力,显著提升测试效率和可靠性。
|
4月前
|
存储 Unix Shell
确定Shell脚本在操作系统中的具体位置方法。
这对于掌握Linux的文件系统组织结构和路径方面的理解很有帮助,是我们日常工作和学习中都可能使用到的知识。以上讲解详细清晰,应用简便,是每一个想要精通操作系统的计算机爱好者必备的实用技能。
102 17
|
3月前
|
测试技术 Python
Python测试报告生成:整合错误截图,重复用例执行策略,调整测试顺序及多断言机制。
如何组织这一切呢?你可以写一本名为“Python测试之道”的动作指南手册,或者创建一个包含测试策略、测试顺序、多断言机制的脚本库。只要你的测试剧本编写得足够独到,你的框架就会像一位执行任务的超级英雄,将任何潜伏于代码深处的错误无情地揪出来展现在光天化日之下。这些整理好的测试结果,不仅有利于团队协作,更像冒险故事中的精彩篇章,带给读者无尽的探索乐趣和深刻的思考。
106 10
|
4月前
|
Linux Shell
Centos或Linux编写一键式Shell脚本删除用户、组指导手册
Centos或Linux编写一键式Shell脚本删除用户、组指导手册
120 4
|
4月前
|
Linux Shell 数据安全/隐私保护
Centos或Linux编写一键式Shell脚本创建用户、组、目录分配权限指导手册
Centos或Linux编写一键式Shell脚本创建用户、组、目录分配权限指导手册
265 3
|
5月前
|
Linux Shell
在Linux、CentOS7中设置shell脚本开机自启动服务
以上就是在CentOS 7中设置shell脚本开机自启动服务的全部步骤。希望这个指南能帮助你更好地管理你的Linux系统。
417 25
|
6月前
|
网络协议 Shell 网络安全
面试官想听的不仅是命令——如何结构化回答“容器无Shell时如何测试外网”?
“说说看,如果一个Pod的容器没有Shell,如何测试它能否访问外网?”
面试官想听的不仅是命令——如何结构化回答“容器无Shell时如何测试外网”?