소프트웨어 테스팅은 소프트웨어가 의도대로 동작하는지 검증하는 과정이다. 결함을 조기에 발견해 수정 비용을 줄이고 품질을 보장한다.
/E2E / (적음, 느림, 비쌈)
/통합테스트 / (중간)
/ 단위 테스트 / (많음, 빠름, 저렴)
python
# 테스트 코드
import pytest
def add(a, b):
return a + b
def test_add():
assert add(2, 3) == 5
assert add(-1, 1) == 0
assert add(0, 0) == 0
def test_add_type_error():
with pytest.raises(TypeError):
add("2", 3)
# 픽스처
@pytest.fixture
def user():
return {"name": "Alice", "age": 30}
def test_user_age(user):
assert user["age"] >= 18
모킹 (Mocking)
python
from unittest.mock import patch, MagicMock
def test_send_email():
with patch('myapp.email.send') as mock_send:
mock_send.return_value = True
result = create_user("alice@example.com")
mock_send.assert_called_once_with("alice@example.com")
assert result.email == "alice@example.com"
관련 개념
참고문헌
- •Fowler, M. Testing strategies in a microservice architecture
- •pytest 공식 문서: pytest.org