1. Testing on unittest frame:
IF the __name__ == " __main__ " : unittest.main () # the unittest instance frame will identify the beginning of the method to test_ use cases, simultaneously performed automatically # total by the number of cases is performed: at the beginning of the example method test_ total # the total number of failures with the embodiment, is an example of a method throws an exception Total # plurality case execution sequence: ASCII code ordering method name. # View ASCII code: ord ()
2. batch execution of test cases
# All the modules added to the suite # can automatically run all the modules Import unittest from Python_0715_unittest Import two_num_multy AS num_multy from Python_0715_unittest Import two_num_add AS num_add # 1. Create a test suite one_suite = unittest.TestSuite () # 2. by module bulk load test Case # define test loader object # into the loading test in the suite after loader module one_loader = unittest.TestLoader () one_suite.addTest (one_loader.loadTestsFromModule (num_multy)) # execution sequence related to the order of addition of the suite one_suite.addTest (one_loader.loadTestsFromModule (num_add)) # execution Example # Creates an execution object one_runner = unittest.TextTestRunner () one_runner.run (one_suite) # result executed, F for failure use cases, representative of the success with Example # Ctrl + Shift +
Import unittest # all start with test py file path # . py file represents the folder where one_suite = unittest.defaultTestLoader.discover ( " . " ) # one_suite = unittest.defaultTestLoader.discover (r "F: \ python_homework \ Python_0715_unittest ") one_runner = unittest.TextTestRunner () one_runner.run (one_suite)