import requests
import unittest
url="http://www.imooc.com"
data={
“username”:“cs”,
“password”:“123”
}
class TestCase01(unittest.TestCase):
def setUp(self):
print(“case开始执行”)
def tearDown(self):
print("case执行结束")
@classmethod#加classmethod只执行一次
def setUpClass(cls):
print("case类开始执行")
@classmethod
def tearDownClass(cls):
pass
def test_01(self):
# res=requests.get(url=url,params=data).json()
data1={
"user":"1111"
}
self.assertDictEqual(data1,data)
def test_02(self):
data1={
"username":"cs",
"password":"123"
}
self.assertDictEqual(data1,data,msg="这两个字典不相等")
def test_03(self):
flag=True
self.assertFalse(flag,msg="不等于FALSE")
def test_04(self):
flag=False
self.assertFalse(flag,msg="不等于false")
def test_05(self):
flag="111"
flag1="2222"
self.assertEqual(flag,flag1,msg="字符串不相等")
def test_06(self):
flag="asdasdasd"
flag1="as"
self.assertIn(flag1,flag,msg="不包含")
if name == ‘main’:
# unittest.main()
suite=unittest.TestSuite()
#case执行管理
# suite=unittest.TestSuite()
suite.addTest(TestCase01(“test_06”))
runner=unittest.TextTestRunner
runner.run(suite)
# tests=[TestCase01('test06'),TestCase01('test03'),TestCase01('test02'),TestCase01('test04'),TestCase01('test05'),TestCase01('test01')]
# suite.addTests(tests)
# runner=unittest.TextTestRunner()
# runner.run(suite)