수동 기능 테스트 작성

FastAPI 입문

Matt Eckerle

Software and Data Engineering Leader

기능 테스트란?

시스템 테스트

  • 초점: 개별 시스템 동작
  • 목적: 시스템 기능 검증
  • 범위: 엔드포인트
  • 환경: 앱이 실행 중인 Python 환경
def test_read():
    response = client.get("/items/1")
    assert response.status_code == 200

기능 테스트

  • 초점: 통합된 시스템
  • 목적: 전체 시스템 검증
  • 범위: 애플리케이션
  • 환경: 앱이 실행 중인 Python 환경
def test_delete_then_read():
    response = client.delete("/items/1")
    assert response.status_code == 200
    response = client.get("/items/1")
    assert response.status_code == 404
FastAPI 입문

테스트 워크플로

성공/실패 테스트 워크플로 예시 다이어그램

FastAPI 입문

기능 테스트 워크플로 예시

성공 워크플로

  • 생성 후 조회
  • 생성 후 수정
  • 생성 후 삭제
  • ...

실패 워크플로

  • 생성 없이 조회
  • 삭제 후 수정
  • 생성 없이 삭제
  • ...
FastAPI 입문

기능 테스트 스크립트

  • 테스트 프레임워크 외부 - "수동 테스트"
  • requests 사용
import requests
ENDPOINT = "http://localhost:8000/items"
# Create item "rock"
r = requests.post(ENDPOINT, json={"name": "rock"})
assert r.status_code == 200
# Get item rock
r = requests.get(ENDPOINT, json={"name": "rock"})
assert r.status_code == 200
  • 알려진 애플리케이션 상태 기반으로 워크플로 구성
FastAPI 입문

실습해 봅시다!

FastAPI 입문

Preparing Video For Download...