一、unittest
1、unittest是python自帶的
2、使用:
a. class繼承unittest.TestCase
b. 方法用test開頭
c. 可單獨運行方法,也可直接運行類(只運行test開頭的方法)
d. 命令行:python -m unittest -v 模塊.類名 -k 匹配某用例關(guān)鍵字
e. 跳過:用例加裝飾器@unittest.skio(“說明”)
3、參數(shù)化
a. 類上@ddt.ddt
b. 測試用例@ddt.file_data('文件路徑'),用例的入?yún)⑹?,參?shù)化了幾個就穿幾個
4、其他
a. 用例描述'''xxxxx'''
b. 報告模板beautifulReport
使用python xxx.py的方式才能生成報告
import beautifulReport as bf
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestDemo)
runner = bf(suite)
runner.report(filename='diff', description='test_diff_report')
c.測試夾具(setUp,tearDown,setUpClass,tearDownClass)
d. 框架大概:https://www.cnblogs.com/yangyang521/p/10073060.html
e. 常用斷言

二、flask的一點點(俺只用了皮皮毛)
參考博客:https://blog.csdn.net/weixin_43778491/article/details/86661285
1、特點:輕量,靈活
2、配置在run.py
3、路由在方法上加@app.route('/test',methods=["GET"])
4、flask自帶json處理類jsonify
5、設(shè)置IP地址端口和調(diào)試狀態(tài):app.run(host='0.0.0.0',port=8000,debug=True)
6、request常用屬性:
request.args.get('key')
request.form.get('key')

三、django皮皮毛
參考博客:http://c.biancheng.net/view/7288.html
1、MTV 是 Model-Template-View

2、django常用命令:
a. 創(chuàng)建項目:django-admin startproject 項目名
b. 創(chuàng)建app,先進入項目目錄后:django-admin startapp 應(yīng)用名
c. 更改/同步表,在manage.py層:python manage.py makemigrations 和 python manage.py migrate
d. 創(chuàng)建超管:python manage.py createsuperuser
e. 啟動服務(wù):python manage.py runserver 0.0.0.0:8000
3、常用目錄和文件
a. 項目下的同名目錄中:
- settings.py是配置文件,可設(shè)置模板目錄,數(shù)據(jù)庫之類
- urls.py設(shè)置路由,正則匹配用re_path()
b.應(yīng)用目錄下:
- templates目錄:html文件
- models.py:實體類,orm(對象關(guān)系映射Object Relational Mapping,用于實現(xiàn)面向?qū)ο缶幊陶Z言里不同類型系統(tǒng)的數(shù)據(jù)之間的轉(zhuǎn)換),字段類型參考:https://blog.csdn.net/qq_38059635/article/details/87274142
- views.py:邏輯處理,常用的返回類型from django.shortcuts import render(返回頁面),HttpResponse(返回字符串或json),HttpResponseRedirect(重定向)
- admin.py:在django的后臺是否展示實體類的設(shè)置
4、django和flask的對比:
直接參考:https://www.jb51.net/article/172702.htm