import unittest class TestStringMethods(unittest.TestCase): def test_upper(self): self.assertEqual('hello'.upper(), 'HELLO') if __name__ == '__main__': unittest.main()
import unittest class TestMath(unittest.TestCase): def test_addition(self): self.assertEqual(2 + 2, 4) def test_subtraction(self): self.assertEqual(4 - 2, 2) if __name__ == '__main__': unittest.main()In this example, we create a test case class called TestMath. Inside the class, we define two test methods: test_addition and test_subtraction. These methods verify that adding and subtracting two numbers returns the expected result. We use the assertEqual method to make these assertions. The unittest library is a built-in Python module that provides a framework for testing code.