Flask-Testing 单元测试

Flask-Testing官网:

https://pythonhosted.org/Flask-Testing/
http://flask.pocoo.org/docs/testing/

Flask 中文文档
http://dormousehole.readthedocs.org/en/latest/


准备

1. 安装pip
2. 安装Flask
3. 安装Flask-Testing (ver:>=0.4.1)

测试程序

#coding=utf8
from flask import Flask,jsonify
from flask.ext.testing import TestCase
import unittest

app = Flask(__name__)

@app.route("/ajax/")
def some_json():
    return jsonify(success=False)

class TestViews(TestCase):
    def create_app(self):
        app.config['TESTING'] = True
        return app

    def test_some_json(self):
        response = self.client.get("/ajax/")
        '''
               判断还回的JSON对像是不是{'success':True}
        '''
        self.assertEquals(response.json, dict(success=True))

if  __name__ =='__main__':
    unittest.main()


执行测试结果:

python tests.py



已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页