-
Notifications
You must be signed in to change notification settings - Fork 4
Test Generation Guide
This document provides a comprehensive guide on how tests are generated for the Da Vinci Prior Authorization Support (PAS) Test Kit, how to use the generator, and some insights into its mechanics for maintainers.
A portion of the server tests within the Da Vinci PAS Test Kit, particularly those related to profile validation and must-support element checks, are programmatically generated. This approach ensures that the test kit remains aligned with the specific version of the PAS Implementation Guide (IG) it targets and reduces the manual effort required to update tests when new IG versions are released or when profiles change.
The test generator processes the formal artifacts of the PAS IG (such as StructureDefinitions and CapabilityStatements) to create executable test code.
Note that any time you make changes to content in the
lib/davinci_pas/generator directory, you will need to regenerate the tests.
Do not make changes to the generated directory directly, because these will be
overwritten during the next generation.
Before you can generate tests, ensure you have the following set up:
- Ruby Environment: The test kit and its generator are written in Ruby. You'll need a working Ruby installation.
-
Bundler: The project uses Bundler to manage Ruby gems (dependencies). Install it with
gem install bundler. -
Project Dependencies: From the root directory of the
davinci-pas-test-kit, runbundle installto install all required gems. -
PAS IG Package: You need the
.tgzpackage file for the specific version of the Da Vinci PAS IG you want to generate tests for. This package contains the machine-readable artifacts (profiles, extensions, value sets, etc.).
Follow these steps to generate a new test suite or update an existing one for a specific PAS IG version:
-
Obtain the IG Package:
- Download the
package.tgz(or similarly named.tgzfile) for the desired Da Vinci PAS IG version. This is typically available from the HL7 FHIR IG registry or the IG's publication page.
- Download the
-
Place the IG Package:
- Navigate to the
lib/davinci_pas_test_kit/igs/directory within your local clone of thedavinci-pas-test-kitrepository. - Place the downloaded
.tgzfile into thisigs/directory. - It's good practice to rename the file to clearly indicate the IG version, for example,
davinci_pas_2.0.1.tgzordavinci_pas_2.1.0.tgz. The generator might infer the version from the filename or internal package metadata.
- Navigate to the
-
Run the Generator Task:
- Open your terminal and navigate to the root directory of the
davinci-pas-test-kit. - Execute the Rake task for PAS test generation:
bundle exec rake pas:generate - This command will invoke the scripts located in
lib/davinci_pas_test_kit/generator/.
- Open your terminal and navigate to the root directory of the
-
Verify Generated Files:
- After the generator runs, check the
lib/davinci_pas_test_kit/generated/directory. You should see a new subdirectory corresponding to the IG version you targeted (e.g.,v2.0.1/). - Inside this version-specific directory, you'll find generated Ruby files containing test groups, profile validation tests, must-support tests, and other necessary components.
- Also, check
lib/davinci_pas_test_kit/metadata.rbto ensure the new suite ID (if a new version was added) is registered.
- After the generator runs, check the
-
Test the Generated Suite:
- Run your local Inferno instance (
./run.shafter./setup.sh). - In the Inferno UI, you should now see the newly generated (or updated) test suite available for selection.
- Execute some of the generated tests to ensure they load correctly and behave as expected. Test against a reference implementation or sample data if possible.
- Run your local Inferno instance (
The test generation logic resides primarily in the lib/davinci_pas_test_kit/generator/ directory. Key components include:
-
ig_loader.rb: Responsible for loading and parsing the IG package (.tgzfile), making its resources (StructureDefinitions, CapabilityStatements, etc.) accessible. -
ig_metadata_extractor.rb/ig_metadata.rb: Extracts high-level metadata from the IG. -
suite_generator.rb: Orchestrates the generation of an entire test suite for an IG version. -
group_generator.rb/group_metadata.rb: Handles the creation of test groups within the suite. -
must_support_test_generator.rb: Specifically generates tests for "must support" elements defined in profiles. It inspects StructureDefinitions to identify these elements and creates tests to verify their presence or handling. -
validation_test_generator.rb: Generates tests that perform FHIR profile validation on resources. -
naming.rb: Provides conventions for naming generated files, classes, and test IDs. -
Templates: The generator likely uses ERB (Embedded Ruby) templates (often found within the
generator/templates/subdirectory, though not explicitly listed in the initial file view) to structure the generated Ruby code for tests and groups.
The general process is:
- The Rake task invokes the main generator script.
- The IG package is loaded.
- Relevant resources (profiles, capability statements) are identified.
- For each profile, tests are generated for:
- Basic resource validation against the profile.
- Validation of "must support" elements.
- Potentially tests for specific operations or interactions defined in CapabilityStatements.
- These tests are organized into groups, and the groups form a test suite.
- The generated Ruby files are written to the
lib/davinci_pas_test_kit/generated/<ig_version>/directory.
Maintaining or extending the generator requires a good understanding of Ruby, the Inferno Framework's testing DSL (Domain Specific Language), and the structure of FHIR Implementation Guide packages.
Test kit documentation is stored within the ./docs folder of
this repository and is automatically synchronized to this wiki with each update
to the main branch using the Publish Docs Wiki
workflow. Do not change content
within this wiki directly as changes will be overwritten.
Using this Test Kit
Client Suite
Server Suite
Contributing to this Test Kit
Reference Documents & External Links