Ler*_*rve 7 python unit-testing atom-editor
我正在尝试使用Atom编辑器,并想知道如何使用键盘快捷键运行Python单元测试.
Ler*_*rve 12
安装
单元测试示例test.py
编写单元测试并将其另存为test.py.
import unittest
class MyTest(unittest.TestCase):
def test_pass(self):
pass
def test_fail(self):
call_method_that_does_not_exist()
if __name__ == '__main__':
unittest.main()
Run Code Online (Sandbox Code Playgroud)运行单元测试
控制台输出
因为单元测试test_fail会失败,这将是控制台输出:
E.
======================================================================
ERROR: test_fail (__main__.MyTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/Lernkurve/Desktop/PythonDemos/a.py", line 9, in test_fail
call_method_that_does_not_exist()
NameError: global name 'call_method_that_does_not_exist' is not defined
----------------------------------------------------------------------
Ran 2 tests in 0.000s
FAILED (errors=1)
[Finished in 0.047s]
Run Code Online (Sandbox Code Playgroud)