To achieve this, unittest
supports some important concepts:
-
test fixture
- A test fixture represents the preparation needed to perform one or moretests, and any associate cleanup actions. This may involve, for example,creating temporary or proxy databases, directories, or starting a serverprocess. test case
-
A
test case is the smallest unit of testing. It checks for a specificresponse to a particular set of inputs.
unittest
provides a base class,TestCase
, which may be used to create new test cases.
test suite
- A test suite is a collection of test cases, test suites, or both. It isused to aggregate tests that should be executed together. test runner
- A test runner is a component which orchestrates the execution of testsand 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 ofexecuting the tests.
- 详解Python的单元测试 (Quote)
单元测试可以有效地测试某个程序模块的行为,是未来重构代码的信心保证。单元测试的测试用例要覆盖常用的输入组合、边界条件和异常。
单元测试代码要非常简单,如果测试代码太复杂,那么测试代码本身就可能有bug。
单元测试通过了并不意味着程序就没有bug了,但是不通过程序肯定有bug。
- python单元测试unittest实例详解
- Python单元测试框架unittest使用方法讲解
- Python中unittest用法实例
- Python中的测试模块unittest和doctest的使用教程
- Python单元测试框架unittest简明使用实例
- Python中unittest模块做UT(单元测试)使用实例
- Python之PyUnit单元测试实例
- 在Python中进行自动化单元测试的教程
- 对Python的Django框架中的项目进行单元测试的方法
- 利用Python中unittest实现简单的单元测试实例详解
- Questions
- When using 'assertRaise' , the function is not executed.
class TestSolver(TestCase): def test_negative_discr(self): s = Solver self.assertRaises(Exception,s.demo,3,0,1) #s.demo not executed def test_demo(self): self.fail()
- When using 'assertRaise' , the function is not executed.