Skip to content

TestPlan Shorthand (TPH)

TestPlan Shorthand (TPH) is a concise DSL for authoring FHIR TestPlan resources, in the same spirit as FHIR Shorthand (FSH) for profiles.

Experimental

TPH is under active development alongside the FHIR R5 TestPlan specification.

Why TPH?

A FHIR TestPlan JSON file for a simple 3-case suite is ~80 lines. The equivalent TPH is ~10 lines:

TestPlan: PatientSuite
Title: "Patient API Test Suite"
Status: #active

TestCase: PatientCreate
  TestRun: TestScript/patient-create

TestCase: PatientRead
  Dependency: PatientCreate
  TestRun: TestScript/patient-read

TestCase: PatientDelete
  Dependency: PatientRead
  TestRun: TestScript/patient-delete
{
  "resourceType": "TestPlan",
  "id": "PatientSuite",
  "title": "Patient API Test Suite",
  "status": "active",
  "testCase": [
    {
      "key": "PatientCreate",
      "testRun": [
        { "script": { "reference": "TestScript/patient-create" } }
      ]
    },
    {
      "key": "PatientRead",
      "dependency": [
        { "predecessor": { "reference": "#PatientCreate" } }
      ],
      "testRun": [
        { "script": { "reference": "TestScript/patient-read" } }
      ]
    },
    {
      "key": "PatientDelete",
      "dependency": [
        { "predecessor": { "reference": "#PatientRead" } }
      ],
      "testRun": [
        { "script": { "reference": "TestScript/patient-delete" } }
      ]
    }
  ]
}

Syntax Reference

TestPlan Header

TestPlan: <id>
Title: "<human-readable title>"
Description: "<optional description>"
Status: #<draft|active|retired>
Url: "http://example.org/TestPlan/<id>"

TestCase

TestCase: <key>
  Title: "<optional title>"
  TestRun: <TestScript reference>

Dependencies

TestCase: <key>
  Dependency: <OtherCaseKey>
  TestRun: <TestScript reference>

Multiple dependencies:

TestCase: ComplexCase
  Dependency: CaseA
  Dependency: CaseB
  TestRun: TestScript/complex-test

TestData

TestCase: CaseWithData
  TestData: Patient/example-patient
  TestRun: TestScript/patient-test

Full Example

TestPlan: AUCorePatientSuite
Title: "AU Core Patient Test Suite"
Description: "Validates AU Core Patient profile conformance"
Status: #active
Url: "http://example.org/TestPlan/au-core-patient"

TestCase: PatientCreate
  Title: "Create AU Core Patient"
  TestRun: TestScript/au-core-patient-create

TestCase: PatientSearchByMedicare
  Title: "Search by Medicare Number"
  Dependency: PatientCreate
  TestRun: TestScript/au-core-patient-search-medicare

TestCase: PatientSearchByIHI
  Title: "Search by IHI"
  Dependency: PatientCreate
  TestRun: TestScript/au-core-patient-search-ihi

TestCase: PatientCleanup
  Dependency: PatientSearchByMedicare
  Dependency: PatientSearchByIHI
  TestRun: TestScript/au-core-patient-delete

Using TPH Files

TPH files (.tph) are compiled to JSON at build time and used exactly like hand-authored TestPlan JSON:

Ant build
<fhirtest testPlan="tests/au-core-patient.tph"
          serverUrl="http://localhost:8080/fhir"/>
JUnit 5
@TestFactory
Stream<DynamicNode> auCore(FhirTestConfig config) {
    return new TestPlanProvider(config).provide("au-core-patient.tph");
}

Next Steps