# Types of Testing
# ================
# Unit Testing:
# - Tests individual components or functions in isolation.
# - Ensures that each part of the code works correctly on its own.
#
# Integration Testing:
# - Tests the interaction between different components or modules.
# - Ensures that integrated parts of the application work together.
#
# Testing in Python
# =================
# unittest
# - Built-in module in Python
# - Provides a framework for writing and running tests.
# - Inspired by the JUint framework from Java.
# pytest
# - Third-party testing framework.
# - Simple syntax, powerful features.
# - Supports fixtures, parameterized testing, and plugins.
import unittest
class TestExample(unittest.TestCase):
def test_add(self):
self.assertEqual(1+1, 2)
if __name__ == '__main__':
unittest.main()
# Key Points:
# ===========
# - Test Case: A class that inherits from unittest.TestCase to
# define test methods.
# - Assertions: Method like assertEqual that check conditions
# and validate test outcomes.
# - Execution: Use unittest.main() to automatically discover
# and run tests when the script is executed directly.
# Output:
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
댓글 영역