- 论坛徽章:
- 0
|
本帖最后由 zhycjh 于 2018-05-19 14:33 编辑
我有下面的一小段测试代码,声明了一个unittest.TestCase的继承类:
import unittest
class mytest(unittest.TestCase):
def __init__(self,methodName='runTest'):
super(mytest,self).__init__(methodName)
print '__init__'
def setUp(self):
print '----setUp'
def tearDown(self):
print '----tearDown'
def testTrue1(self):
print "true1 begin"
self.assertTrue(True)
print "true1 end"
def testTrue2(self):
print "true2 begin"
self.assertTrue(True)
print "true2 end"
if __name__=="__main__":
unittest.main()
代码输出:
__init__
__init__
----setUp
true1 begin
true1 end
----tearDown
.----setUp
true2 begin
true2 end
----tearDown
.
----------------------------------------------------------------------
Ran 2 tests in 0.003s
OK
1. 不是每个case都调用一次__init__然后setUp,而是先__init__了两次。这是为什么?
2. 为什么每次tearDown结束之后,会另起一行并且打印一个"."号?
谢谢
|
|