import unittest class TestDict(unittest.TestCase): def test_dict_equal(self): dict1 = {'apple': 3, 'banana': 2, 'orange': 1} dict2 = {'banana': 2, 'orange': 1, 'apple': 3} self.assertDictEqual(dict1, dict2, "Dictionaries are not equal") if __name__ == '__main__': unittest.main()
import unittest class TestDict(unittest.TestCase): def test_dict_not_equal(self): dict1 = {'apple': 3, 'banana': 2, 'orange': 1} dict2 = {'banana': 3, 'orange': 2, 'apple': 1} self.assertDictEqual(dict1, dict2, "Dictionaries are not equal") if __name__ == '__main__': unittest.main()In this example, the method test_dict_not_equal compares two different dictionaries. The test fails because the dictionaries are not the same. Package Library: unittest (built-in library in Python)