Testing Strategy
The eight testing layers that back this crate: schema drift guards, golden corpus, snapshots, property tests, fuzzing, cross-implementation compatibility, doctests, and the feature matrix.
rubo4e uses eight testing layers, plus a set of targeted integration tests.
πTest Layer Summary
| Layer | Purpose | Location | Run |
|---|---|---|---|
| 0. Drift guard | Committed codegen matches the schemas | tests/generated_contract.rs | cargo test --features versioned --test generated_contract |
| 1. Golden | Wire round-trip | tests/golden/ | cargo test --features json,versioned --test golden |
| 2. Snapshot | JSON Schema output stability | tests/snapshots/ | cargo test --all-features --test schemars_snapshots |
| 3. Property | Identifier, enum and date round-trips | tests/proptest_roundtrips.rs | cargo test --all-features --test proptest_roundtrips |
| 4. Fuzz | Panic safety | fuzz/ | cargo +nightly fuzz run <target> |
| 5. Compat | Cross-implementation interop | tests/compat/ | cargo test --features json,versioned --test compat |
| 6. Doctest | Documentation is executable | rustdoc in src/ | cargo test --all-features --doc |
| 7. Feature matrix | Every feature builds warning-free | CI job / justfile | just lint-features |
just ci runs everything CI runs, locally.
time and decimal replace field types, so the generator emits a second declaration for each affected field that --all-features never compiles. just test-schema-fallback runs the suite with those two off; it is part of just ci.
Two Criterion benches are measured rather than asserted: benches/json_perf.rs (German deserialization, German and canonical serialization) and benches/timeseries_perf.rs (the coverage audit over a day, a month and a settlement year, across clean and pathological series).
πLayer 0 β Schema Drift Guards
src/generated/ is committed, so nothing at build time forces it to agree with generator/schemas/. These tests read both sides and compare:
- every schema emitted exactly one Rust module, and no module is left over
- every struct stamps the
_typits schema pins β BOs and COMs - every struct stamps the
_versionits schema declares BoTyp/ComTypvariants are named after the structs they discriminate- no two BO4E wire values collapse onto one Rust enum variant
just check-docs-drift regenerates and diffs, catching anything these assertions do not name. See Code Generator.
πLayer 1 β Golden Tests
Deserialize committed BO4E payloads, re-serialize with to_json_german(), and check the result decodes back to an equal value, with unknown fields preserved.
tests/golden/
βββ vertrag_minimal.json # only _typ + _version
βββ vertrag_typical.json
βββ marktlokation_{minimal,typical}.json
βββ messlokation_{minimal,typical}.json
βββ netzlokation_{minimal,typical}.json
βββ rechnung_{minimal,typical}.json
βββ lastgang_minimal.json # only the required zeitIntervallLaenge
βββ lastgang_typical.json # a clean quarter-hourly hour in kW
βββ zeitreihe_minimal.json
βββ zeitreihe_typical.json # the same hour as kWh readingsThe schema version is each file's "_version"; there is no version subdirectory. The two time-series fixtures must also audit clean and integrate to the same 450 kWh β see Time Series & Units.
πLayer 2 β Snapshot Tests
insta snapshots of the schemars JSON Schema for Marktlokation, Vertrag and Sparte. They need schemars, versioned, time and decimal. Review intentional changes with cargo insta review; an unreviewed change fails CI.
πLayer 3 β Property-Based Tests
proptest (a plain dev-dependency) checks:
- every identifier type:
DisplayβFromStrround-trip, with strategies that generate the base and letfrom_base/from_prefixderive the check digit - EIC object type and the restricted EIC types; OBIS spelling-independence and canonical form
- enum
DisplayβFromStrover every known variant (Sparte,BoTyp) date_serde/opt_date_serderound-trips,nullβNone, and the"YYYY-MM-DD"wire form
The Arbitrary impls are #[cfg(test)] only. To reuse the strategy pattern in your own crate, see Ecosystem.
πLayer 4 β Fuzz Testing
Feed arbitrary bytes to the deserializers and validators; any panic, stack overflow or memory-safety violation is a failure. An Err is not.
CI only type-checks the targets (fuzz/ is its own workspace, so cargo check --workspace does not see it); just check-fuzz does the same locally. Running them needs nightly and cargo-fuzz, and is done locally or on demand:
cargo install cargo-fuzz
cargo +nightly fuzz run fuzz_deserialize_vertrag # until stopped
cargo +nightly fuzz run fuzz_deserialize_vertrag -- -runs=1000000 # bounded run
cargo +nightly fuzz run fuzz_deserialize_vertrag fuzz/artifacts/fuzz_deserialize_vertrag/<id> # reproducefuzz/fuzz_targets/
βββ fuzz_deserialize_marktlokation.rs β identifiers, Ortsangabe exclusivity
βββ fuzz_deserialize_vertrag.rs β date-time ordering
βββ fuzz_deserialize_rechnung.rs β multi-Betrag arithmetic, currency agreement
βββ fuzz_deserialize_kosten.rs β Kostenposition line totals; the `Value` reader and both recursive walks
βββ fuzz_deserialize_bilanzierung.rs β nested temporal ranges
βββ fuzz_deserialize_lastgang.rs β large Zeitreihenwert arrays; depth and budget limits; the coverage audit
βββ fuzz_deserialize_zeitreihenwert.rs β the per-entry time-series hot path
βββ fuzz_parse_identifiers.rs β every identifier parser, the duration and time-of-day parsersEach BO target decodes the same bytes through serde_json::from_slice and the hardened German reader, and validates whatever decoded: the validators do Decimal arithmetic over wire values, and rust_decimal panics on some inputs. The targets build with time, decimal and validate, so the date, time and decimal parsers are fuzzed too.
πLayer 5 β Cross-Implementation Compatibility
Payloads in BO4E-python and go-bo4e output format are decoded and at least three field values per payload asserted; an outbound module checks that rubo4e's own output carries _typ and _version on BOs and COMs.
tests/compat/
βββ README.md β how to regenerate the vectors
βββ python/ β marktlokation, messlokation, rechnung, vertrag
βββ go/ β the same fourπLayer 6 β Doctests
Every rustdoc code block is compiled and run. There are no ignore blocks: an example that cannot be executed is a ```text block, and one that cannot run standalone is no_run (still type-checked). The generator emits the per-enum iter_known / from_wire examples with real assertions taken from the schema.
Examples needing a feature are wrapped so they compile in every configuration:
/// ```
/// # #[cfg(feature = "json")] {
/// // β¦example needing `json`β¦
/// # }
/// ```πLayer 7 β Feature Matrix
--all-features cannot catch code that is dead unless an optional dependency is enabled, bindings left unread when a feature compiles a body away, or a feature that does not build on its own. Every feature is therefore checked alone and in realistic combinations, warnings denied: a CI matrix job, and just lint-features locally.
πOther integration tests
| Test | Checks |
|---|---|
any_bo.rs | AnyBo dispatch on _typ, including every hardened limit through it |
builder.rs | typed-builder behaviour, with compile-fail cases under tests/builder/ui/ |
current_series_alignment.rs | every hand-written module targets the series current does |
enum_from_str.rs | every enum has a strict FromStr that rejects "UNKNOWN" and anything from_wire rejects |
enum_strict.rs | VARIANTS, COUNT, iter_known, as_wire, from_wire |
extension_paths.rs | the recursive Bo4eExtensions check |
hardening_nested.rs | hardened limits apply at every nesting level |
hash_keys.rs | generated types as HashMap / BTreeMap keys; no Hash without Eq |
identifier_schemas.rs | every identifier's schemars and utoipa output agree, with a valid example |
interval_conventions.rs | each interval bound is read the way the schema states |
intervals.rs | Lastgang, Zeitreihe, Energiemenge agree via IntervalReading |
json_strictness.rs | every JSON entry point consumes its whole input and caps nesting |
lokationsbuendel.rs | the bundle audit against every published structure |
modell2.rs | the BK6-20-160 Modell-2 answers on Beyond the Schema |
pinned_tag.rs | the schema tag and MSRV are derived, not written out in workflows, recipes or the site config |
prelude_surface.rs | the prelude re-exports every identifier; Borrow<str> agrees with Hash / Ord |
schema_descriptions.rs | no Rust-facing prose reaches a published schema description |
serde_round_trip.rs | serde round-trips and _typ / _version stamping |
site_examples.rs | the README and site snippets still compile and mean what the prose says |
strict_decode.rs | the recursive Bo4eStrict walker |
struct_sizes.rs | identifier newtypes stay within their size bounds |
timeseries.rs | a Lastgang from JSON through audit to billed energy |
utoipa_compile.rs | key types implement ToSchema |
validation.rs | the garde rules and Validated<T> |
zusatz_attribut.rs | namespaced accessors on every type, and their wire form |