Writing Unit Tests in Python ✅
- Simple and easy just import the Python 3 built-in library
unittest
. - Wrap up tests in a Class.
- Use assert methods.
python
import unittest
class TestSum(unittest.TestCase):
def test_sum(self):
self.assertEqual(sum([1, 2, 3]), 6, "Should be 6")
def test_sum_tuple(self):
self.assertEqual(sum((1, 2, 2)), 6, "Should be 6")
if __name__ == '__main__':
unittest.main()