Python自动化测试脚本的编写可以使用unittest框架。unittest框架是Python内置的单元测试框架,它可以帮助我们编写和运行自动化测试用例。是一个使用unittest框架编写的简单的自动化测试脚本的示例代码:
Python自动化测试脚本的编写可以使用unittest框架。unittest框架是Python内置的单元测试框架,它可以帮助我们编写和运行自动化测试用例。是一个使用unittest框架编写的简单的自动化测试脚本的示例代码:
python
import unittest
class TestStringMethods(unittest.TestCase):
def test_upper(self):
self.assertEqual('foo'.upper(), 'FOO')
def test_isupper(self):
self.assertTrue('FOO'.isupper())
self.assertFalse('Foo'.isupper())
def test_split(self):
s = 'hello world'
self.assertEqual(s.split(), ['hello', 'world'])
# check that s.split fails when the separator is not a string
with self.assertRaises(TypeError):
s.split(2)
if __name__ == '__main__':
unittest.main()
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(77条)