配置项目默认使用pytest


这里配置的-s参数是让print函数能够正常打印出啦.
编写测试用例
编写pytest测试样例非常简单,不需要继承TestCase类.只需要按照下面的规则:
测试文件以test_开头(以test结尾也可以)
测试类以Test开头,并且不能带有 init 方法
测试函数以test开头
断言使用基本的assert即可
# content of test_class.py
class TestClass:
def test_one(self):
x = "this"
assert 'h' in x
def test_two(self):
x = "hello"
assert x == 'check'
运行测试用例.
如果右击TestClass
,然后点击运行,会运行这个类下面的所有测试用例.

如果右击test_one
然后点击运行,只会运行这个函数.

网友评论