tornado 单元测试

之前的项目都是用django开发,django写单元测试很方便

tornado的好处是异步,而且有websocket

tornado的单元测试用到了 unittest,例子如下

from tornado.test.util import unittest
from tornado.testing import AsyncHTTPTestCase
from tornado.web import Application

from xxxx import TestHandler
#TestHandler就是被测试的模块

class BaseTest(AsyncHTTPTestCase):
    def setUp(self):
        pass
        super(BaseTest, self).setUp()


class WebHandlerTest(BaseTest):

    def get_app(self):
        return Application([
            ('/test/', TestHandler),
        ])

    def test_sub(self):
        body = 'hello world'
        response = self.fetch('/test/', method='POST', body=body)
        self.assertEqual(response.code, 200)


if __name__ == '__main__':
    unittest.main()
原文地址:https://www.cnblogs.com/yemsheng/p/4193027.html