Import the unittest DEF the Add (A, B): return A + B Import HTMLTestRunner Import BeautifulReport AS BFR class AddTest (of unittest.TestCase): @classmethod DEF : setUpClass (CLS) # execute it until all cases performed with Print ( ' setUpClass ' ) @classmethod DEF tearDownClass (CLS): # all use cases it is performed after performing Print ( ' tearDownClass ' ) DEF the setUp (Self): Print ( ' the setUp ') # Each Example performed before it will be executed with DEF the tearDown (Self): Print ( ' the tearDown ' ) # each embodiment will be executed after executing it with DEF test_normal (Self): # two test Result = the Add (1,1 ) self.assertEqual ( 2 , Result) Print ( ' test_normal ' ) DEF test_error (Self): Print ( ' test_error ' ) Result = the Add (1,1 ) self.assertEqual ( . 1, Result,' The results miscalculation ' ) # Dead Format File = Open ( ' report.html ' , ' wb ' ) # To generate test reports, first open a file Runner = HTMLTestRunner.HTMLTestRunner (File, title = ' test report ' ) # specified which file written into the inside spread, title to specify a title test_suite = unittest.makeSuite (AddTest) # use makeSuite is to automatically AddTest class which traverse all added test_suite inside runner.run (test_suite) # pass a test set to come to run all the tests collection file.close ()
Any pay is worth it, getting better