The TestScript Generator is an open source, command-line tool for generating Fast Healthcare Interoperability Resources (FHIR) TestScript resources. It requires a FHIR Implentation Guide (IG) to direct how it creates TestScripts.
Clone this repository and navigate to your local copy. Once there, run: bundle install
, followed by bundle exec bin/testscript_generator
. This will start the generator within the context of your local copy.
ig_directory=[path]
: overrides the default ig directory, which is ./igs
output_path=[path]
: overrides the default output directory, which is ./generated_testscripts
[type]
: specifies a specific test type to generate. If none are provided, then all types are generated. If one or more are provided, then only those specified types are generated. See below for the supported types..tgz
or .zip
form and pointed to by the optional ig_directory=
command-line argument.The TestScript Generator aims to ease the testing process by creating a suite of FHIR TestScript instances to be executed against FHIR servers to check conformance to a given Implementation Guide (IG). FHIR IGs include formal definitions of data structure requirements, interaction patterns, and other details that can be used to generate tests. By attempting to use this information to generate tests as TestScript instances the TestScript Generator project seeks to provide feedback to the FHIR community around
This generator is intended to be used in concert with the TestScript Engine: users can auto-create TestScripts with this generator and then execute them against endpoint(s) with the engine.
The generator currently contains several approaches to generation that reflect the experimental nature of this functionality. The common threads are:
Within this framework, a few different approaches to generation have been tried:
Current experience suggests that a combination of direct templating and building are effective and creation of a library of functions to build common patterns would be worthwhile.
The generator can currently generate 4 types of tests. The following sections provide details on their capabilities and status.
The profile read tests are simple tests that read a supplied instance and validate conformance to a profile. In addition, generation supports the creation of a combined search and read test that will use some additional information to create patient-specific searches for profile instances to remove the need to provide individual instance ids and instead provide only a single patient id.
To generate these specific tests, run bundle exec bin/testscript_generator read
/igs
directoryextra_input/[IG file name, no extension]/profile_scope_search_spec.csv
and if present, uses the information to create a combined search and read test.Uses the template approach under the templates directory:
profile_scope_search_spec.csv
within the extra_input/[ig directory]
folder where [ig directory]
will be the name of the loaded zip or tgz file containing the IG without the extention (example for the mCODE pre-STU3 build from December 2022). The csv will have 3 columns with headers profile
, search
, and returnsOnlyProfile
. Each row has the following information in these columns
profile
: name of the profile from the StructureDefinition name
element. Profiles in the IG that don't have a corresponding row are not included in the combined test.search
: search criteria that would go into a FHIR search url, e.g. code=http://loinc.org|89243-0
to search on a specific LOINC code. Currently only supports a single criteria and the =
operator. May also be SPECIFIC
if no scoping search is possible for the profile, in which case a input variable for a specific instance id is included in the generated TestScript. Must be at least one row with the value ROOT
which indicates this is the patient profile to use. May also be empty if searching on the resource type is sufficient. When a search is performed, the search will also be restricted to the specific patient.returnsOnlyProfile
: true
if all returned instances will/must conform to the profile. false
if not all of them will necessarily conform. Not used when search
is SPECIFIC
or ROOT
.These read tests are simple and robust. The user experience is not good using the individual tests, but the combined test relies on profiles that have a search that returns only that profile. This is the most complete generation case to date and seems promising, but will need more work on the engine and generation side to fine-tune the feedback and usability.
Must Support tests check that for elements flagged as MustSupport
within a profile, an instance can be provided that demonstrates the server's ability to expose data in that form. The theory is that if it can be demonstrated on at least one resource, then that proves that the system supports it.
To generate these specific tests, run bundle exec bin/testscript_generator mustSupport
/igs
directoryMustSupport
elements within itUses the template approach under the templates directory:
These tests are a solid work in progress. They will work for many common MustSupport patterns, including choice types, some slices. They don't currently generate tests for complex or nested slices and have trouble with multiple response References and cases where multiple profiles are allowed. In addition, the need to provide a specific instance id for each test means that they aren't currently practical to use. Recently added support for subtest execution in the engine may support completing unimplemented cases and improving the use experience.
Search Parameter tests check that a server supports searching using specific criteria. The tests currently generated focus on cross-resource parameters that can be used on any resource type.
To generate these specific tests, run bundle exec bin/testscript_generator search
/igs
directoryUnder the generators directory:
These generated tests currently will not execute and represent a rough idea about how search parameters could be tested. Additional work needed to
Interaction tests are designed to check whether a server supports the API interactions required by the IG, such as the ability to create, update, read, and search for resource instances.
To generate these specific tests, run bundle exec bin/testscript_generator interaction
/igs
directoryread
, write
, search
Currently, the generator can create two types of TestScripts. The first tests single resource-level interactions on individual resource types (e.g., read an AllergyIntolerance or create a Patient). These tests are known as interaction conformance tests. A second type of tests the generator creates are the basic search parameter tests, which test whether the implementation supports interactions with simple search params (e.g. _id
). Both types of tests depend on the Capability Statement being included within the consumed IG.
Under the testscript_generator directory
These generated tests currently will not execute and represent a rough idea about how interactions could be tested. Additional work needed to
The TestScript Generator supports several extensions to the TestScript resource that the TestScript Engine also supports. Details on these extensions are their use can be found in this IG. Feedback on the need for and approach to these extensions welcome.
Copyright 2022 The MITRE Corporation
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.