unittest

Stdlib — TestingPython 2.0+Intermediate

Built-in unit testing framework (TestCase, assertions, runners)

Quick Info

Documentation
Official Docs
Python Version
2.0+
Dependencies
None — Python Standard Library
Install
Included with Python

Learn by Difficulty

Quick Example

python
import unittest

class TestMath(unittest.TestCase):
    def test_add(self):
        self.assertEqual(1 + 1, 2)

    def test_multiply(self):
        self.assertEqual(3 * 4, 12)

# Run tests
suite = unittest.TestLoader().loadTestsFromTestCase(TestMath)
runner = unittest.TextTestRunner(verbosity=2)
runner.run(suite)

The unittest module is part of Python's standard library. Built-in unit testing framework (TestCase, assertions, runners).

Try in Playground

Tags

stdlibtestingassertionoop

Related Items