SYSTEM Cited by 1 source
Randomizer (Swift)¶
What it is¶
Randomizer is an open-source Swift library
(github.com/kandelvijaya/Randomizer)
authored by Vijaya Kandel (Zalando Mobile, iOS) that ships
a Random protocol + Standard Library conformances to support
randomised-input testing in Swift codebases. Used inside
Zalando's iOS codebase as the generator substrate for the
"never hand-type constants into test cases" discipline
(Source: sources/2021-02-01-zalando-stop-using-constants-feed-randomized-input-to-test-cases).
Interface¶
The core surface is a single protocol plus a .random static
property:
protocol Random {
static var random: Self { get }
}
// Standard Library conformances shipped by the library
extension String: Random { /* ... */ }
extension Int: Random { /* ... */ }
extension Bool: Random { /* ... */ }
// etc — "most of the used types in the Standard Library"
Call site:
Swift's type inference at the assignment site resolves .random
to the concrete type's conformance
(type-class-driven
random generator).
User-defined type extension¶
User code adds conformance for project-local types by delegating
to per-field .random:
struct LabelProps: Codable, Hashable {
let text: String
let backgroundColor: String?
let font: FontProps
}
extension LabelProps: Random {
public static var random: LabelProps {
return LabelProps(
text: .random,
backgroundColor: .random,
font: .random
)
}
}
Nested types compose: LabelProps.random calls
FontProps.random calls String.random, all via protocol
dispatch.
What it is (and isn't) solving¶
Solves:
- Constant-input test antipattern
— makes
.randomcheaper to write than hand-typed constants, so developers actually use it. - Ergonomic dispatch. One name, per-type resolution, no generator-name-management overhead.
- Composition. User types conform by delegating — no hand-written threading.
Does not (per the 2021 post) solve:
- Shrinking. No mention of test-case minimisation. Random failures report whatever the RNG produced, not the minimal reproducer.
- Seed replay. No mention of deterministic failure reproducibility. Rerunning a failing test without the seed may or may not reproduce.
- Run volume. Idiomatic usage in the post is one random value per test run, not thousands. Mature PBT libraries run generators ≥10⁴ times per property.
- Build-time codegen. Kandel flags but does not ship
derived
Random— user types still hand-write the conformance body. - Stateful / model-based testing. Out of scope; the library is purely about one-shot value generation.
These gaps place Randomizer at the entry-level of the PBT tooling spectrum, far below Hypothesis (Python), proptest (Rust), or fast-check (JS). The 2021 post frames it as a gateway drug to the discipline, not a full-featured PBT framework.
Positioning on the wiki¶
Randomizer is the wiki's canonical example of type-class- driven random generator at mobile / iOS implementer altitude. The pre-existing PBT Seen-ins cluster at backend / storage altitudes:
| Seen-in | Altitude | Language |
|---|---|---|
| systems/canopycheck (Dropbox) | sync-engine planner | Rust |
| systems/shardstore (AWS S3) | storage engine + spec | Rust |
| MongoDB Mobile SDK (TLA+) | conformance checking | Spec + C++ |
| Randomizer (Zalando) | iOS UI / view-model testing | Swift |
The altitude gap matters: PBT is well-known at storage /
consensus / planner altitudes (where the invariants are
typed and narrow). At mobile-UI altitude — random view-models
rendered through UILabel and asserted on — PBT is much less
commonly practiced. Randomizer is evidence that the pattern
generalises down the stack, even if the run-volume and
shrinker discipline doesn't travel with it.
Provenance¶
- Author: Vijaya Kandel (Zalando Mobile, iOS engineer in 2021).
- Public repo: github.com/kandelvijaya/Randomizer.
- Technique attribution: Kandel credits Jorge Ortiz's 2017 Swift Aveiro Clean Architecture workshop for the "don't use constants on tests" phrase. The Swift library is Kandel's own.
- Adoption: "At Zalando, we use this Randomizer library." No disclosed external-adoption numbers.
Seen in¶
- sources/2021-02-01-zalando-stop-using-constants-feed-randomized-input-to-test-cases
— canonical disclosure. Walkthrough of the
Randomprotocol - Standard Library conformances + user-type extension
(
LabelProps: Random) + mobile-UI test example (LabelComponent+MockNode) + escape hatches for constrained types (String.randomEmailvsEmail: Randomnewtype).
Related¶
- patterns/property-based-testing — the pattern Randomizer implements at the entry level.
- concepts/type-class-driven-random-generator — the dispatch mechanism.
- concepts/example-based-test-constant-input-antipattern — the antipattern Randomizer targets.
- companies/zalando — open-source parent.
- patterns/seed-recorded-failure-reproducibility — complementary discipline not in Randomizer's 2021 surface.
- concepts/test-case-minimization — shrinker discipline not in Randomizer's 2021 surface.