測試教程網.unittest教程.6. 命令行接口
阿新 • • 發佈:2018-08-13
http 命令行 com unit int clas -m ack ttr
From: http://www.testclass.net/pyunit/commind_line_interface/
背景
unittest支持命令行接口,我們可以在命令行裏指定運行具體的測試用例。
實例
在test_password_1.py
中定義了PasswordTeseCase
用例,我們可以從命令行中指定只運行該用例。
$ python -m unittest test_password_1.PasswordTeseCase
set up
.set up
F
======================================================================
FAIL: test_week_password (test_password_1.PasswordTeseCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/easonhan/code/testclass.net/src/pyunit/test_password_1.py", line 21, in test_week_password
self.assertTrue(passwd != ‘password123‘, msg)
AssertionError: False is not true : user tom has a weak password
----------------------------------------------------------------------
Ran 2 tests in 0.001s
FAILED (failures=1)
還可以使用-v參數來獲得更詳細的輸出
$ python -m unittest test_password_1.PasswordTeseCase -v
test_dummy (test_password_1.PasswordTeseCase) ... set up
ok
test_week_password (test_password_1.PasswordTeseCase) ... set up
FAIL
======================================================================
FAIL: test_week_password (test_password_1.PasswordTeseCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/easonhan/code/testclass.net/src/pyunit/test_password_1.py", line 21, in test_week_password
self.assertTrue(passwd != ‘password123‘, msg)
AssertionError: False is not true : user tom has a weak password
----------------------------------------------------------------------
Ran 2 tests in 0.001s
FAILED (failures=1)
也可以在命令行中一次指定多個測試用例類,具體的大家可以自己嘗試一下。
測試教程網.unittest教程.6. 命令行接口