这里分为了两种情况:
E2E:接近真实使用情况,用例数量少
UT:执行速度快,用例数量多
1、整理测试点
1、注册功能
- 允许匿名访问
- URL:http://127.0.0.1:8000/accounts/register/
- get请求:返回html
- post请求:提交json参数,返回json响应
- 用户名不能为空
- 密码不能为空
- 两次密码必须相同
- 密码长度不能小于6
- 用户名不能重复
- 参数正确,则返回:注册成功
2、登录
-
允许匿名访问
-
URL:http://127.0.0.1:8000/accounts/register/
-
get请求:返回html
-
post请求:提交表单,返回了重定向
-
用户名不能为空
-
密码不能为空
-
密码不能错误
3、提交反馈
-
不允许匿名访问
-
URL:http://127.0.0.1:8000/lili/submit/
-
GET:返回HTML
-
POST::提交json,返回json
- 提交的数据会入库
- 提交的数据会和用户关联
- 同一用户,不可重复发布
4、反馈的结果
- 允许匿名访问
- URL:http://127.0.0.1:8000/lili/result/
- 所有的请求返回:HTML
2、编写测试代码
主要学习两个部分的内容
1、django自带的测试组件
2、pytest-django插件
1、测试http请求

这个Client自己是一个客户端,同时也是一个服务端
import pytest
from django.http import HttpResponse
from django.test.client import Client
# Create your tests here.
@pytest.fixture
def client()->Client:
return Client()
def test_register(client:Client):
res:HttpResponse = client.get('/accounts/register/')
assert res.status_code ==200
html:str=res.content.decode('utf-8')
assert "账号" in html
assert "密码" in html
assert "确认

最低0.47元/天 解锁文章
1023

被折叠的 条评论
为什么被折叠?



