当前位置:网站首页>Generating test reports using the unittest framework

Generating test reports using the unittest framework

2022-06-21 17:01:00 Expert of explosive liver fist

Generate test reports
Case code :
Testcase.py file :

import unittest

class Test_case(unittest.TestCase)# Inherit TestCase class :
    # start 
    def setUp(self):
        print(' All use case execution starts !!!')
    # end 
    def tearDown(self):
        print(' All use case execution ends !!!')

    def test_ab(self):
        print('ab Use case execution -------')
        a = 1
        b = 1

        # Judge by assertion a And b Whether it is equal or not 
        self.assertEqual(a,b,'a And b identical ')

    def test_cd(self):

        c=7
        d=1
        print('cd Use case execution --------')
        self.assertEqual(c,d,'c And d atypism ')


Testsuit.py file :

import unittest
from HTMLTestRunner import HTMLTestRunner

from AA.Testcase import Test_case

# Construct test suite ( Test flow )
testsuite=unittest.TestSuite()

# Add test case 
testsuite.addTest(Test_case('test_ab'))# call Test_case Class test_ab Method 
testsuite.addTest(Test_case('test_cd'))# call Test_case Class test_cd Method 

# establish report.html Test report 
file=open('./report.html','wb')
runner=HTMLTestRunner(stream=file,title=' Test report ',description=' Perform the report ')
runner.run(testsuite)
file.close()

Generated test report :
 Insert picture description here

原网站

版权声明
本文为[Expert of explosive liver fist]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206211318465118.html