Repository navigation
Expand file tree
/
Copy pathtest_HTMLTestRunnerCN.py
More file actions
98 lines (75 loc) · 2.43 KB
/
Copy pathtest_HTMLTestRunnerCN.py
File metadata and controls
98 lines (75 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# -*- coding:utf-8 -*-
import unittest
import HTMLTestRunnerCN
#测试用例
class MyTestCase(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def testCase1(self):
self.assertEqual(2,2,"testCase_Pass")
def testCase2(self):
self.assertEqual(2,3,"testCase_Fail")
def testCase3(self):
self.assertEqual(2,5,"测试用例_不通过")
def testCase4(self):
self.assertEqual(2,2,"testCase_Error")
testCase_Error
def testCase5(self):
pass
def testCase6(self):
self.assertEqual(2,2,"testCase_Error")
Findyou
class APITestCase(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def testCase1(self):
self.assertEqual(2, 2, "testCase_Pass")
print("测试打印日志~")
def testCase2(self):
self.assertEqual(3, 3, "testCase_Pass")
print("测试打印日志~")
def testCase3(self):
self.assertEqual(5, 5, "testCase_Pass")
def testCase4(self):
self.assertEqual(2, 1, "测试用例_不通过")
def testCase5(self):
self.assertEqual(2, 9, "测试用例_不通过")
def testCase6(self):
pass
#添加Suite
def Suite():
#定义一个单元测试容器
suiteTest = unittest.TestSuite()
#将测试用例加入到容器
suiteTest.addTest(MyTestCase("testCase1"))
suiteTest.addTest(MyTestCase("testCase2"))
suiteTest.addTest(MyTestCase("testCase3"))
suiteTest.addTest(MyTestCase("testCase4"))
suiteTest.addTest(MyTestCase("testCase5"))
suiteTest.addTest(MyTestCase("testCase6"))
suiteTest.addTest(APITestCase("testCase1"))
suiteTest.addTest(APITestCase("testCase2"))
suiteTest.addTest(APITestCase("testCase3"))
suiteTest.addTest(APITestCase("testCase4"))
suiteTest.addTest(APITestCase("testCase5"))
suiteTest.addTest(APITestCase("testCase6"))
return suiteTest
if __name__ == '__main__':
#确定生成报告的路径
filePath ='/Users/albert/PycharmProjects/HTMLTestRunnerCN/ReportCN.html'
fp = open(filePath,'wb')
#生成报告的Title,描述
runner = HTMLTestRunnerCN.HTMLTestReportCN(
stream=fp,
title='自动化测试报告',
#description='详细测试用例结果',
tester='Findyou'
)
#运行测试用例
runner.run(Suite())
# 关闭文件,否则会无法生成文件
#fp.close()