Testing a UCUM converter against contrived numbers proves it can add. Testing it against clinical fixtures — realistic analyte values, boundary cases from clinical guidelines, edge cases from national code sets — proves it can be trusted with real integration traffic. Every converter that goes to production should have a fixture set that a clinician would recognise. The site's Clinical UCUM unit converter is fixture-tested; teams shipping their own should be too. For the wider FHIR framing, more practical FHIR walkthroughs has more.
Build The Fixture Set From Real Ranges
- Glucose fasting normal: 70-99 mg/dL = 3.9-5.5 mmol/L
- Sodium normal: 135-145 mmol/L = 310-333 mg/dL (mass conversion)
- Potassium normal: 3.5-5.0 mmol/L = 137-196 mg/dL
- Creatinine normal: 0.6-1.2 mg/dL = 53-106 umol/L
- HbA1c normal: 4-5.6% (dimensionless) = 20-38 mmol/mol IFCC
Each range gives you two-point conversion tests. Each analyte has a specific molecular weight; the converter has to know it.
For the categorical picture, unit conversion errors that reach clinical decisions covers what goes wrong when this is skipped.
Test Boundary Values
- Zero — some converters produce NaN or divide-by-zero on empty inputs
- Very small — 0.001 to expose prefix errors
- Very large — 10000 to expose overflow or precision loss
- Negative — should reject; clinical quantities do not go negative
Boundary values are where prefix bugs and precision bugs surface. Skipping them means the bugs live until real data hits them.
Test Temperature Specifically
Temperature is affine — subtraction plus multiplication. Standard fixtures:
- 0 Cel = 32 [degF]
- 37 Cel = 98.6 [degF]
- 100 Cel = 212 [degF]
- 0 K = -273.15 Cel
Converters that treat temperature as linear produce spectacular errors on the freezing and boiling points.
Test The Analyte-Specific Cases
For every mass-to-molar conversion, the analyte matters. Fixtures should include:
- Glucose 100 mg/dL = 5.56 mmol/L (MW 180)
- Cholesterol 200 mg/dL = 5.17 mmol/L (MW 386.7)
- Urea 30 mg/dL = 5.00 mmol/L (MW 60)
- Calcium 10 mg/dL = 2.50 mmol/L (MW 40)
A converter that uses one divisor for all is silently wrong for three of the four. For the prefix side, prefix and exponent handling that's easy to miss is the entry.
Test Unit Cancellation
When the input and output units are the same, the converter should return the value unchanged. 5 mg/dL → mg/dL = 5 mg/dL. Converters that apply a phantom conversion factor produce off-by-a-tiny-amount errors.
Test Roundtrips
A → B → A should return A within floating-point tolerance. Roundtrip failures indicate accumulated precision loss or an asymmetric conversion path.
Roundtrip testing surfaces subtle bugs that single-direction testing misses.
Test Rejection Of Unknown Units
xyz— no such UCUM codemg/xyz— unknown denominator- Empty string — no code at all
The converter should reject each explicitly. Silent identity fallback is worse than rejection.
Automate The Fixture Runs
Fixtures should run in CI on every change to the converter. Manual verification is not enough for a component that touches clinical values. For the canonical set that the fixtures rest on, canonical UCUM units the FHIR spec assumes you'll use is the entry.
The Short Version
Fixtures anchored to clinical guideline ranges. Boundary values. Analyte-specific for concentration conversions. Temperature explicitly. Cancellation and roundtrip tests. Explicit rejection of unknowns. CI automation. That is the fixture set that keeps a clinical converter safe.

Sources
- UCUM canonical specification - UCUM canonical specification
