Otestuj svůj endpoint

Vývoj softwaru s Claude Code

Dani Zysman

AI Curriculum Manager @ DataCamp

Uzavři kruh

recraft: half: Vývojář slaví po zobrazení zelených, úspěšných testů na monitoru, s ikonami zaškrtnutí a databáze

  • Kapitola 2: Jednotkové testy jednotlivých funkcí
  • Kapitola 3: Vytvoření endpointu s MCP + Pydantic
  • Teď: Otestuj celé řešení od začátku do konce

Stejný postup: požádej Claude, aby napsal testy!

Vývoj softwaru s Claude Code

Jednotkové vs. integrační testy

Jednotkové testy izolují jednu funkci pomocí mocků; integrační testy ověřují celý tok od požadavku po odpověď

Vývoj softwaru s Claude Code

Projekt doposud

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
Vývoj softwaru s Claude Code

Napiš testy a spusť je

> 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!
Vývoj softwaru s Claude Code

Pojďme cvičit!

Vývoj softwaru s Claude Code

Preparing Video For Download...