Most FHIR APIs pass a conformance test once, before go-live, and then change every week. A renamed field, a new search parameter or a refactored error handler can break a partner's app without any alarm, because nothing checks the API on each commit.
This post is for engineering teams that build or run FHIR servers, facades and client libraries. It explains which automated tests belong in continuous integration, how to run the HL7 FHIR Validator and profile checks there, and how to test search, paging and error responses.
What is FHIR API testing for healthcare interoperability?
Building or extending a FHIR API?
See how we design and deliver FHIR integrations that partners can rely on after every release.
FHIR API testing for healthcare interoperability is the practice of checking, on every code change, that a FHIR API still returns valid resources, follows the profiles it claims, searches and pages correctly and reports errors in a standard form. Agnotic Technologies builds these suites into the same pipeline that builds the API.
A conformance run proves an API was right on the day of the test. Automated tests in continuous integration keep it right after every merge.
Which tests should run on every code change?
Every code change should run fast checks that fail the build: resource validation, profile checks, search and paging tests and error response tests. Slower suites, such as a full conformance run, can run nightly.
- Unit tests: the mapping code that turns internal records into FHIR resources, one test per field rule.
- Validation: every resource type the API can return, run through the HL7 FHIR Validator against its declared profiles.
- API tests: real HTTP calls to a test instance covering read, search, paging and errors.
- Contract check: the CapabilityStatement compared with a reviewed snapshot so silent changes show up.
- Nightly: a full conformance suite and a larger set of production-shaped synthetic data.
Keep the per-commit suite short enough that nobody is tempted to skip it. Move anything slow to the nightly run rather than deleting it.
How does the HL7 FHIR Validator fit into CI?
The validator runs as a build step over resources generated by your own code, not over hand-written samples. That way the check covers what the API actually produces.
HL7 defines validating a FHIR resource as checking its structure, cardinality, value domains, code bindings, invariants and profile rules, and publishes the FHIR Validator as a Java jar provided as part of the specification.
- Generate: run the mapping code over test records and write each output resource to a folder.
- Validate: run the validator over the folder with the FHIR version and implementation guide packages pinned.
- Fail: treat errors as build failures and track warnings in a reviewed baseline file.
- Pin: use a fixed validator version, and upgrade it in its own pull request.
Code checks depend on terminology access. Decide whether the build reaches a terminology server or defers code validation to the nightly run, and record that choice.
Profile checks against the guides you claim
A profile check confirms that resources meet the rules of the implementation guides the API claims, such as US Core. The base specification allows far more than a profile does, so base validation alone misses absent required elements.
- Declared profiles: resources list the profiles they claim in meta.profile, and the build validates against each one.
- Must Support elements: tests assert that mapped data appears whenever the source record has it.
- Version pins: the guide version in the build matches the one in your CapabilityStatement.
When a new guide version arrives, add it as a second validation target before switching. The difference in errors becomes the upgrade work list.
How should search and paging be tested?
Search and paging should be tested against fixed data sets where the correct answer is written down in advance. Each test sends a query and compares the returned ids, totals and links with the expected set.
The FHIR R4 RESTful API says servers should support paging for search and history results using continuation links such as next in the returned Bundle, and that a server need not return the number of results asked for with _count but cannot return more.
- Parameters: each supported search parameter, alone and in the combinations clients use, including date prefixes such as ge and lt.
- Paging: follow every next link to the end and check that no resource repeats or goes missing.
- Limits: a _count above the server maximum returns at most the maximum, never an error page.
- Unknown parameters: the API rejects or ignores them exactly as your documentation says.
Paging bugs often appear only when data changes between page requests. Add a test that inserts a record part way through paging and checks the documented behavior still holds.
What should error responses look like?
Error responses should be OperationOutcome resources with a fitting HTTP status code, not stack traces or HTML pages. Client developers parse them to decide whether to retry, fix the request or stop.
In FHIR R4, OperationOutcome is a collection of error, warning or information messages that result from a system action, and each issue carries a required severity (fatal, error, warning or information) and a required issue type code.
- Bad request: an invalid parameter returns 400 with an OperationOutcome that names the parameter.
- Not found: an unknown id returns 404 and an OperationOutcome that reveals nothing else about the record.
- Not allowed: a token without the right scope returns 403 with no resource data in the body.
- Server error: a 500 carries an OperationOutcome with a correlation id and no internal details.
Run the error tests through the same gateway and load balancer that production uses. Many HTML error pages come from layers in front of the FHIR code, not from the code itself.
Test data without real patients
Test data should be synthetic and shaped like production, never copied from a live system. Real records in a CI log or test report are a privacy incident waiting to be found.
- Fixtures: a small, hand-built set of patients whose expected search results are written down.
- Generated records: synthetic patients in volume for paging and load checks.
- Edge cases: missing names, merged patients, future dates and the longest values your sources allow.
- Access cases: patients a test token may not see, so scope rules are checked by search as well as by read.
Version the fixtures with the code. A commit that changes both a fixture and its expected result deserves a second reviewer.
Mistakes that let broken FHIR APIs ship
Most FHIR regressions reach partners through gaps in the test setup rather than missing tests. These are the gaps that show up most often.
- Hand-written examples: the validator passes perfect samples while the real mapping produces invalid output.
- Ignored warnings: hundreds of warnings hide the one that becomes an error in the next guide version.
- Single page tests: search tests that never follow a next link miss paging bugs.
- Errors as HTML: a gateway or framework default returns a web page instead of an OperationOutcome.
- Unpinned tools: a new validator release fails the build with no code change.
Each one lets a release pass its own tests and still break a partner's app the next morning.
A worked example: a medication list API
A worked example: a team adds MedicationRequest search to a FHIR facade over a pharmacy system. The pull request includes mapping unit tests, three new fixture patients and written expected results for search by patient, status and date.
The build generates resources from the fixtures and validates them against the US Core profile the API claims. One resource fails because a pharmacy status was mapped to a code outside the required value set.
The developer fixes the mapping. The API tests then follow paging to the end with a small _count, and an error test confirms that an invalid status parameter returns 400 with an OperationOutcome. Only then does the change merge.
Who owns FHIR API tests and their inputs?
The API team owns the tests, but other people own their inputs. Name each owner so that a failing check always has someone to fix it.
- API team: mapping tests, API tests, fixtures and the pipeline itself.
- Interoperability lead: which guides and versions the API claims, and the warning baseline.
- Partner developers: reports of failures their apps see, each turned into a regression test.
- Security reviewers: scope tests and checks that errors leak no data.
Agree how quickly a red build must be fixed and who may mark a test as skipped. A skipped test with no owner and no end date has, in practice, been deleted.
How do you measure FHIR test coverage?
Measure coverage against what the API promises, not only lines of code. The CapabilityStatement lists the resources, interactions and search parameters you support, so each entry should map to at least one test.
- Interaction coverage: every resource and interaction in the CapabilityStatement has a test.
- Profile coverage: every claimed profile has validated examples generated by the real mapping.
- Error coverage: every documented error path returns a tested OperationOutcome.
- Escaped defects: issues partners find that the tests missed, tracked per release.
Publish these numbers with each release. A falling escaped-defect count is the clearest sign the suite is doing its job.
What are FHIR API testing best practices?
Validate the resources your code generates, not samples, and pin the validator and guide versions. Test search with known answers, follow every next link and require an OperationOutcome on every error.
Keep synthetic fixtures under version control, map each CapabilityStatement entry to a test, and turn every partner-reported bug into a regression test.
How can Agnotic help test a FHIR API in CI?
Agnotic builds FHIR APIs and the test suites that guard them: validator steps in CI, profile checks, search and paging tests, error contracts and synthetic fixtures. We can add these to an existing FHIR server or facade without changing its design.
Add automated FHIR tests to your pipeline
We set up validation, API tests and coverage reports that run on every merge.
Related reading on Agnotic
FHIR design, paging and testing in healthcare.


