安装安装Atom编辑器
按如下方式安装Script包:
a)启动原子
b)按Ctrl+Shift+p,键入“安装软件包和主题”,然后按Enter打开软件包视图
c)搜索“script”并安装软件包
单元测试示例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()
运行单元测试
控制台输出
因为单元测试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]