from test_case.business.register_business import RegisterBusiness
import unittest
import HtmlTestRunner
import os
class FirstCase(unittest.TestCase):
""“
case层
”""
def setUp(self):
self.register_b = RegisterBusiness('chrome')
def tearDown(self):
print("case后置条件")
def test_register_email_error(self):
email_error = self.register_b.register_email_error('qwe', '程柔位', '123456', '23456')
self.assertFalse(email_error, 'case执行') # 断言是否为false
@unittest.skip("不执行这一条")
def test_register_username_error(self):
name_error = self.register_b.register_name_error('qwe@123.com', '1', '123456', '23456')
self.assertFalse(name_error)
@unittest.skip("不执行这一条")
def test_register_password_error(self):
password_error = self.register_b.register_password_error('qwe@123.com', 'chengtouwei', '1234', '23456')
self.assertFalse(password_error)
@unittest.skip("不执行这一条")
def test_register_code_error(self):
code_error = self.register_b.register_code_error('qwe@123.com', 'chengtouwei', '123456', '23456')
self.assertFalse(code_error)
def test_register_success(self):
success = self.register_b.register_succes('qwe@123.com', 'chengtouwei', '123456', '23456')
self.assertTrue(success)
if name == ‘main’:
f_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(file))))
file_path = os.path.join(f_path + “/report/” + ‘first_case.html’)
f = open(file_path, “wb”)
# unittest.main()
suite = unittest.TestSuite()
suite.addTest(FirstCase(‘test_register_email_error’))
# unittest.TextTestRunner().run(suite)
run = HtmlTestRunner.HTMLTestRunner(stream=f, report_title=“this is first report”, descriptions=u"这个是测试报告",
verbosity=2)
run.run(suite)
运行结果
Traceback (most recent call last):
File “/Users/xiachengpeng/PycharmProjects/pythonProject/test_case/case/firse_case.py”, line 52, in
run.run(suite)
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/HtmlTestRunner/runner.py”, line 67, in run
self.stream.writeln()
File “/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/runner.py”, line 26, in writeln
self.write(’\n’) # text-mode streams translate to \r\n if needed
TypeError: a bytes-like object is required, not ‘str’