เขียนและรัน Integration Test
Blueprint db_routes.py จากบทที่ 3.3 ถูกรวมเข้ากับ Music Analytics API แล้ว ดูได้ที่นี่: music-analytics-api-with-db-routed-validated/db_routes.py โดยจะคืนค่าอัลบั้มตามศิลปินพร้อมการตรวจสอบความถูกต้องด้วย Pydantic:
class Album(BaseModel):
AlbumId: int
Title: str
class ArtistAlbumsResponse(BaseModel):
artist_id: int
artist_name: str
albums: list[Album]
@db_routes.route("/artists/<int:artist_id>/albums")
def get_artist_albums(artist_id):
# Queries chinook.db, returns 404 if artist not found
...
ตอนนี้คุณอยู่ใน music-analytics-api-with-db-routed-validated/ และตั้งค่า MCP ไว้เรียบร้อยแล้ว ให้ขอให้ Claude เขียน pytest integration test ตรวจสอบโค้ดที่ได้ แล้วจึงรันทดสอบ
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การพัฒนาซอฟต์แวร์ด้วย Claude Code
คำแนะนำการฝึกหัด
- เริ่มต้น Claude Code ด้วยคำสั่ง
claude - อ้างอิง
@db_routes.pyแล้วขอให้ Claude เขียน pytest integration test สำหรับ endpoint นี้ - เมื่อเทสต์ดูเรียบร้อยดีแล้ว ให้ขอให้ Claude รันเทสต์นั้น
- เมื่อเสร็จแล้ว พิมพ์
/exitเพื่อออกจาก Claude Code
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำจริง
เปลี่ยนทฤษฎีให้เป็นการลงมือทำด้วยแบบฝึกหัดเชิงโต้ตอบหนึ่งในของเรา
เริ่มแบบฝึกหัด