我被一些单元测试卡住了。
这是我能想到的最简单的例子:
#testito.py
import unittest
class Prueba(unittest.TestCase):
def setUp(self):
pass
def printsTrue(self):
self.assertTrue(True)
if __name__=="__main__":
unittest.main()
问题是,运行此命令无效:
$ python testito.py
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
我挠头,因为上面的代码没有任何问题。现在发生了几次测试,我真的不知道下一步该怎么做。任何想法?
缺省情况下,仅运行以名字开头的函数test
:
class Prueba(unittest.TestCase):
def setUp(self):
pass
def testPrintsTrue(self):
self.assertTrue(True)
测试用例通过子类创建
unittest.TestCase
。这三个单独的测试使用名称以字母开头的方法定义test
。该命名约定将告知测试运行者哪些方法表示测试。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句