初识unittest

unittest介绍:

  unitest是python版本的junit测试框架,支持测试自动化、共享测试设置和关闭代码,测试用例组合管理及生成对应的测试报告

unittest四大功能:

test fixture

test fixture represents the preparation needed to perform one or more tests, and any associate cleanup actions. This may involve, for example, creating temporary or proxy databases, directories, or starting a server process.

  支持一个或多个的测试组件,以及清除测试动作,例如:创建或临时数据库链接,目录及启动服务器进程等操作。

test case

test case is the smallest unit of testing. It checks for a specific response to a particular set of inputs. unittest provides a base class, TestCase, which may be used to create new test cases.

  测试用例是测试的各个单元,检查了一个特定输入的响应,unittest提供了一个基类,TestCase用于创建新的测试用例。

test suite

test suite is a collection of test cases, test suites, or both. It is used to aggregate tests that should be executed together.

  一个测试套件是测试案例,测试套件,或两者的集合。它用于汇总应一起执行的测试。

test runner

test runner is a component which orchestrates the execution of tests and provides the outcome to the user. The runner may use a graphical interface, a textual interface, or return a special value to indicate the results of executing the tests.

  测试运行可以使用命令窗口或者界面运行特定的测试用例,返回对应的测试结果

unittest的第一个例子:

import unittest

class TestNumMethod(unittest.TestCase):

def test_one(self):
self.assertIn(2,[1,2,3])

def test_two(self):
self.assertEqual("1",1)

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

 

posted @ 2019-10-29 20:04  测试爬虫  阅读(157)  评论(0编辑  收藏  举报