单元测试未运行 [英] Unit Test not running
问题描述
我被一些单元测试卡住了.
I'm getting stuck with some unittests.
这是我能想到的最简单的例子:
Here's the simplest example I could come up with:
#testito.py
import unittest
class Prueba(unittest.TestCase):
def setUp(self):
pass
def printsTrue(self):
self.assertTrue(True)
if __name__=="__main__":
unittest.main()
问题是,运行这个没有效果:
Problem is, running this has no effect:
$ python testito.py
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
我正在挠头,因为我没有发现上面的代码有任何问题.现在发生了几次测试,我真的不知道下一步该怎么做.有什么想法吗?
I'm scratching my head as I don't see any problem with the code above. It happened with a couple of tests now and I don't really know what to do next. Any idea?
推荐答案
默认情况下,只运行名称以 test
开头的函数:
By default, only functions whose name that start with test
are run:
class Prueba(unittest.TestCase):
def setUp(self):
pass
def testPrintsTrue(self):
self.assertTrue(True)
来自unittest基本示例:
测试用例是通过子类化 unittest.TestCase
创建的.这三个单独的测试是用名称以字母 test
开头的方法定义的.此命名约定告知测试运行器哪些方法代表测试.
A testcase is created by subclassing
unittest.TestCase
. The three individual tests are defined with methods whose names start with the letterstest
. This naming convention informs the test runner about which methods represent tests.
这篇关于单元测试未运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!