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

LayerPurposeLocationRun
0. Drift guardCommitted codegen matches the schemastests/generated_contract.rscargo test --features versioned --test generated_contract
1. GoldenWire round-triptests/golden/cargo test --features json,versioned --test golden
2. SnapshotJSON Schema output stabilitytests/snapshots/cargo test --all-features --test schemars_snapshots
3. PropertyIdentifier, enum and date round-tripstests/proptest_roundtrips.rscargo test --all-features --test proptest_roundtrips
4. FuzzPanic safetyfuzz/cargo +nightly fuzz run <target>
5. CompatCross-implementation interoptests/compat/cargo test --features json,versioned --test compat
6. DoctestDocumentation is executablerustdoc in src/cargo test --all-features --doc
7. Feature matrixEvery feature builds warning-freeCI job / justfilejust 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 _typ its schema pins β€” BOs and COMs
  • every struct stamps the _version its schema declares
  • BoTyp / ComTyp variants 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 readings

The 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 ↔ FromStr round-trip, with strategies that generate the base and let from_base / from_prefix derive the check digit
  • EIC object type and the restricted EIC types; OBIS spelling-independence and canonical form
  • enum Display ↔ FromStr over every known variant (Sparte, BoTyp)
  • date_serde / opt_date_serde round-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>  # reproduce
fuzz/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 parsers

Each 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

TestChecks
any_bo.rsAnyBo dispatch on _typ, including every hardened limit through it
builder.rstyped-builder behaviour, with compile-fail cases under tests/builder/ui/
current_series_alignment.rsevery hand-written module targets the series current does
enum_from_str.rsevery enum has a strict FromStr that rejects "UNKNOWN" and anything from_wire rejects
enum_strict.rsVARIANTS, COUNT, iter_known, as_wire, from_wire
extension_paths.rsthe recursive Bo4eExtensions check
hardening_nested.rshardened limits apply at every nesting level
hash_keys.rsgenerated types as HashMap / BTreeMap keys; no Hash without Eq
identifier_schemas.rsevery identifier's schemars and utoipa output agree, with a valid example
interval_conventions.rseach interval bound is read the way the schema states
intervals.rsLastgang, Zeitreihe, Energiemenge agree via IntervalReading
json_strictness.rsevery JSON entry point consumes its whole input and caps nesting
lokationsbuendel.rsthe bundle audit against every published structure
modell2.rsthe BK6-20-160 Modell-2 answers on Beyond the Schema
pinned_tag.rsthe schema tag and MSRV are derived, not written out in workflows, recipes or the site config
prelude_surface.rsthe prelude re-exports every identifier; Borrow<str> agrees with Hash / Ord
schema_descriptions.rsno Rust-facing prose reaches a published schema description
serde_round_trip.rsserde round-trips and _typ / _version stamping
site_examples.rsthe README and site snippets still compile and mean what the prose says
strict_decode.rsthe recursive Bo4eStrict walker
struct_sizes.rsidentifier newtypes stay within their size bounds
timeseries.rsa Lastgang from JSON through audit to billed energy
utoipa_compile.rskey types implement ToSchema
validation.rsthe garde rules and Validated<T>
zusatz_attribut.rsnamespaced accessors on every type, and their wire form