测试教程网.unittest教程.6. 命令行接口
生活随笔
收集整理的這篇文章主要介紹了
测试教程网.unittest教程.6. 命令行接口
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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)也可以在命令行中一次指定多個測試用例類,具體的大家可以自己嘗試一下。
轉載于:https://www.cnblogs.com/Raul2018/p/9466832.html
總結
以上是生活随笔為你收集整理的测试教程网.unittest教程.6. 命令行接口的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Python3.6】之在Windows
- 下一篇: 2019网易校招