Test Your Endpoint

Software Development with Claude Code

Dani Zysman

AI Curriculum Manager @ DataCamp

Close the Loop

recraft: half: A developer celebrating after seeing green passing tests on a monitor, with a checkmark and database icons

  • Chapter 2: Unit tests for individual functions
  • Chapter 3: Built an endpoint with MCP + Pydantic
  • Now: Test the whole thing end-to-end

Same workflow: ask Claude to write the tests!

Software Development with Claude Code

Unit vs Integration Tests

Unit tests isolate one function with mocks; integration tests verify the full flow from request to response

Software Development with Claude Code

The Project So Far

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
Software Development with Claude Code

Write Tests and Run Them

> 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!
Software Development with Claude Code

Let's Practice!

Software Development with Claude Code

Preparing Video For Download...