Skip to content

Authoring TestScripts in FSH

Write TestScript resources using FHIR Shorthand syntax and compile them to JSON with SUSHI as part of your normal IG build.

Workflow

FSH → TestScript Workflow

Status

Planned Feature

Native FSH syntax for TestScript (Instance of TestScript) works today via FHIR Shorthand's generic Instance support. A dedicated TSH→FSH integration is on the roadmap.

Using FSH Instance Syntax

SUSHI supports any resource type via Instance. A TestScript authored in FSH:

input/fsh/tests/PatientCreate.fsh
Instance: patient-create
InstanceOf: TestScript
Usage: #definition
Title: "Patient Create Test"
Description: "Creates an AU Core patient and verifies the response"

* status = #draft
* url = "http://example.org/TestScript/patient-create"
* name = "PatientCreate"

* fixture[+].id = "patient"
* fixture[=].autocreate = false
* fixture[=].autodelete = false
* fixture[=].resource = Reference(au-core-patient-example)

* setup.action[+].operation.type = http://terminology.hl7.org/CodeSystem/testscript-operation-codes#create
* setup.action[=].operation.resource = #Patient
* setup.action[=].operation.sourceId = "patient"
* setup.action[=].operation.responseId = "createResponse"

* setup.action[+].assert.description = "Create returns 201"
* setup.action[=].assert.response = #created
* setup.action[=].assert.warningOnly = false

SUSHI compiles this to fsh-generated/resources/TestScript-patient-create.json.

Using TSH Files Directly

TSH files are simpler to write than FSH Instance syntax. Place .tsh files directly in input/tests/testscripts/ — the Ant build compiles them at test time without SUSHI involvement:

input/
└── tests/
    ├── testscripts/
    │   ├── patient-create.tsh   ← compiled by fhir-frog at test time
    │   └── patient-search.tsh
    └── testplans/
        └── au-core-suite.tph

This is the recommended approach for new IGs.

IG Package Structure

After SUSHI compilation, TestScripts appear in the IG package alongside profiles and examples:

package.tgz
├── package/
│   ├── package.json
│   ├── StructureDefinition-au-core-patient.json
│   ├── TestScript-patient-create.json        ← compiled from FSH or TSH
│   └── TestPlan-au-core-suite.json

Implementers install the package and FHIR Frog reads TestScripts directly from it.

Example: AU eRequesting IG

The AU eRequesting sample IG includes:

fhir-frog-sample/erequesting/
├── input/fsh/
│   └── AUeRequestingServiceRequest.fsh      ← profile
├── tests/
│   ├── testscripts/
│   │   ├── create-draft.json
│   │   ├── activate.json
│   │   ├── complete.json
│   │   └── revoke.json
│   └── fixtures/
│       └── ServiceRequest-draft.json
└── build.xml                                 ← runs tests via Ant

Next Steps