Your First TestScript¶
Write and run a FHIR TestScript from scratch in TSH syntax.
What You'll Build¶
A TestScript that: 1. Creates a Patient resource 2. Reads it back by ID 3. Deletes it (teardown)
Prerequisites¶
- Quick Start completed — FHIR Frog on the classpath
- A running FHIR server (see Testcontainers setup)
Step 1: Create the Fixture¶
Create src/test/resources/fhir/fixtures/patient.json:
{
"resourceType": "Patient",
"name": [
{
"family": "Smith",
"given": ["Jane"]
}
],
"gender": "female",
"birthDate": "1990-06-15"
}
Step 2: Write the TestScript¶
Create src/test/resources/fhir/patient-lifecycle.tsh:
TestScript: PatientLifecycle
Title: "Patient Create, Read, Delete"
Status: #draft
Fixture: patient from "fixtures/patient.json"
Setup:
* operation create Patient from patient as createResponse
* assert response = created
* variable patientId = Patient.id from createResponse
Test: "Read the created patient"
* operation read Patient/${patientId} as readResponse
* assert response = okay
* assert Patient.id = "${patientId}"
* assert Patient.name.family = "Smith"
Teardown:
* operation delete Patient/${patientId}
Step 3: Run It with JUnit¶
@ExtendWith(FhirFrogExtension.class)
class PatientLifecycleTest {
@FhirTestConfig(serverUrl = "http://localhost:8080/fhir",
fixtureBasePath = "src/test/resources/fhir")
@TestTemplate
@TestScriptSource("fhir/patient-lifecycle.tsh")
void patientLifecycle() { }
}
Run with:
Step 4: Check the Output¶
A passing run produces JUnit output like:
With reportDir configured, a FHIR TestReport JSON file is also written.
What Just Happened?¶
Setup: POST /fhir/Patient → 201 Created ✓
Extract Patient.id → "abc123"
Test: GET /fhir/Patient/abc123 → 200 OK ✓
Assert name.family = "Smith" → true ✓
Teardown: DELETE /fhir/Patient/abc123 → 204 No Content
Next Steps¶
- Operations — All supported operation types
- Assertions — Full assertion reference
- Variables — Extract and reuse values
- TestPlan Basics — Organise multiple TestScripts