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 PlaygroundTags
stdlibtestingassertionoop
Related Items
pytest
Package — Testing
Feature-rich testing: fixtures, parametrize, plugins, auto-discovery
doctest
Stdlib — Testing
Test code examples embedded in docstrings
unittest.mock
Stdlib — Testing
Mock objects for tests (Mock, MagicMock, patch)
assert
Keyword
Debugging aid that tests a condition and raises AssertionError if false
coverage
Package — Testing
Measure code coverage; shows untested lines/branches