Python-Unittest Example 1

import unittest


def sum_number(a, b):
return a + b


MyTestCase class (unittest.TestCase):
@classmethod # setUpClass method can guarantee a # default perform before the test case execution
DEF setUpClass (CLS) -> None:
Print ( "setUpClass")

def setUp (self) -> None : # setup for each test case execution method will be executed once before #
Print ( "Setup")

def test_sth(self):
self.assertEqual(True, False)

def test_sum_int(self):
self.assertEqual(sum_number(1, 2), 3)
self.assertEqual(sum_number(100, 200), 300)

def test_sum_number(self):
self.assertEqual(sum_number(1.1, 2.1), 3.2)

def tearDown (self) -> None : # tearDown method means that each test case execution time # after the end of the implementation of
print ( "tearDown")

@classmethod # tearDownClass method after the implementation in all test cases executed once #
DEF tearDownClass (CLS) -> None:
Print ( "tearDown")


print(sum_number(1.1, 2.1))

if __name__ == '_main_':
unittest.man()

Guess you like

Origin www.cnblogs.com/jiangkeji/p/12103735.html