엔드포인트 테스트하기

Claude Code로 배우는 Software Development

Dani Zysman

AI Curriculum Manager @ DataCamp

전체 흐름 마무리하기

recraft: half: 모니터에 녹색으로 테스트 통과 표시가 뜬 것을 보고 기뻐하는 개발자, 체크 표시와 데이터베이스 아이콘과 함께

  • 2장: 개별 함수에 대한 단위 테스트
  • 3장: MCP와 Pydantic으로 엔드포인트 구축
  • 지금: 전체 과정을 엔드투엔드로 테스트

동일한 워크플로: Claude에게 테스트 작성을 요청하세요!

Claude Code로 배우는 Software Development

단위 테스트 vs 통합 테스트

단위 테스트는 모의 객체(mock)로 함수 하나만 분리해서 검증하고, 통합 테스트는 요청부터 응답까지 전체 흐름을 검증합니다

Claude Code로 배우는 Software Development

지금까지의 프로젝트

music-analytics-api/
  app.py
  routes.py
  models.py
  db_routes.py         # Database-backed Blueprint
  chinook.db
  test_routes.py       # Unit tests (Ch.2)
  test_db_routes.py    # <- Integration tests
  CLAUDE.md
Claude Code로 배우는 Software Development

테스트 작성 후 실행하기

> Generate pytest integration tests for @db_routes.py and run them
Test Coverage

TestGetArtistAlbums: Core functionality
- Retrieval, sorting, 404s, invalid IDs

TestDatabaseConnection: Connection handling
- Path, closure on success and error

TestErrorHandling: 500 on database errors
TestResponseFormat: JSON format and field validation

Uses temporary SQLite database, independent of chinook.db

Ran all 23 tests: Passed!
Claude Code로 배우는 Software Development

연습해 봅시다!

Claude Code로 배우는 Software Development

Preparing Video For Download...