码迷,mamicode.com
首页 > 其他好文 > 详细

unittest 6 命令行接口(用命令行方式执行测试用例)

时间:2020-02-10 13:37:35      阅读:46      评论:0      收藏:0      [点我收藏+]

标签:pass   error   指定   set   users   定义   测试用例   src   not   

背景

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 命令行接口(用命令行方式执行测试用例)

标签:pass   error   指定   set   users   定义   测试用例   src   not   

原文地址:https://www.cnblogs.com/candyYang/p/12290328.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!