标签:down testcase 结束 命令 demo sse learn ram errors
import unittest
def add(x, y):
return x + y
class TestLearning(unittest.TestCase):
def setUp(self):
a = 0
a += 1
print(‘a:‘ + str(a))
def test_demo(self):
# a=1/0
self.assertEqual(‘foo‘.upper(), ‘FOO‘)
def test_next(self):
self.assertTrue(1 == 1)
在命令行运行的结果:
(venvtest) rabbit:testframe rabbit$ python -m unittest discover -v qiuzhouxin
test_demo (tests.TestLearning) ... a:1
ok
test_next (tests.TestLearning) ... a:1
ok
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK
解析:每次运行一个testcase都会先运行setUp()
若运行testcase过程中有异常,为测试失败(errors=xx)
若assert断言失败,为测试失败(failures=xx)
tearDown()类似setUp,在每个test方法结束后调用,无论测试结果是fail还是error都会调用
标签:down testcase 结束 命令 demo sse learn ram errors
原文地址:https://www.cnblogs.com/EmptyRabbit/p/9299371.html