forked from findyou/HTMLTestRunnerCN
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_HTMLTestReportEN.py
More file actions
101 lines (77 loc) · 2.81 KB
/
test_HTMLTestReportEN.py
File metadata and controls
101 lines (77 loc) · 2.81 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
99
100
101
# -*- coding:utf-8 -*-
import unittest
import HTMLTestReportEN
#测试用例
class MyTestCase(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def testCase1(self):
self.assertEqual(2,2,"testError")
def testCase2(self):
self.assertEqual(2,3,"testError")
def testCase3(self):
self.assertEqual(2,5,"测试错误")
def testCase4(self):
self.assertEqual(2,1,"测试错误")
def testCase5(self):
pass
class APITestCase(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def testCase1(self):
self.assertEqual(2, 2, "testError")
def testCase2(self):
self.assertEqual(3, 3, "testError")
def testCase3(self):
self.assertEqual(5, 5, "testError")
def testCase4(self):
self.assertEqual(2, 1, "测试错误")
def testCase5(self):
self.assertEqual(2, 6, "testError")
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(APITestCase("testCase1"))
suiteTest.addTest(APITestCase("testCase2"))
suiteTest.addTest(APITestCase("testCase3"))
suiteTest.addTest(APITestCase("testCase4"))
suiteTest.addTest(APITestCase("testCase5"))
suiteTest.addTest(APITestCase("testCase6"))
return suiteTest
'''
问题:代码写的没问题,执行也成功了,但就是无法生成HTMLTestRunner的报告
其实这是编辑器搞得鬼,编辑器为了方便用户执行测试,都有一项功能,可以用编辑器来调用unittest或者nose来执行测试用例,这种情况下,执行的只是用例或者套件,而不是整个文件,写在main里的代码是不会被执行的!!自然无法生成测试报告
我们在如果想要生成测试报告,那么一定要注意右键执行时选择的右键菜单,一定要当做文件执行,不要让编辑器当做用例执行
if __name__ == ‘__main__‘:
if __name__ == ‘python‘:
# 把main修改成自己的文件夹名就可以了
---试了不行
'''
if __name__ == '__main__':
#确定生成报告的路径
filePath ='F:\\HTMLTestReportEN.html'
fp = open(filePath,'wb')
#生成报告的Title,描述
runner = HTMLTestReportEN.HTMLTestRunner(
stream=fp,
title='{ Test Report }',
#description='详细测试用例结果',
tester='Findyou'
)
#运行测试用例
runner.run(Suite())
# 关闭文件,否则会无法生成文件
#fp.close()