How do I test output containing dynamic values like dates, GUIDs, or timestamps?
← Testing · Ref: Q208
EK9 expected output files support type-aware placeholders that match dynamic values. Use {{Type}} syntax for values that change between test runs.
PLACEHOLDER SYNTAX
In expected_output.txt, use {{Type}} placeholders:
Created at: {{DateTime}} ID: {{GUID}} Count: {{Integer}}
AVAILABLE PLACEHOLDERS
{{String}} matches any non-empty text
{{Integer}} matches whole numbers
{{Float}} matches decimal numbers
{{Boolean}} matches true/false
{{Character}} matches a single character
{{Bits}} matches a run of 0s and 1s
{{Date}} matches ISO dates (2026-09-29)
{{Time}} matches times (14:30:00)
{{DateTime}} matches ISO datetimes with offset
{{Duration}} matches ISO durations (P1DT2H)
{{Millisecond}} matches millisecond values (250ms)
{{Money}} matches amounts with currency (10.50#GBP)
{{Colour}} matches hex colours (#FF0000)
{{Resolution}} matches dpi/dpc values
{{Dimension}} matches dimension values
{{RegEx}} matches any non-empty text
{{GUID}} matches UUID format
{{FileSystemPath}} matches file paths
EXAMPLE EXPECTED OUTPUT FILE
For a program that prints a GUID and timestamp:
Record ID: {{GUID}} Created: {{DateTime}} Items: {{Integer}} Active: {{Boolean}}
MIXING FIXED AND DYNAMIC
Placeholders can appear anywhere in a line, for example "User alice created at {{DateTime}} with ID {{GUID}}".
Fixed text is matched exactly; each placeholder matches its type's pattern.
See Q204 for black-box testing. See Q205 for parameterized tests. See Q157 for running tests.
Example
defines module qa.testdeep.placeholders defines program DynamicOutputDemo() stdout <- Stdout() // === DYNAMIC VALUES IN OUTPUT === // When testing, some values change each run. // EK9 expected_output.txt supports placeholders. stdout.println("Dynamic output placeholders:") stdout.println(" {{String}} - any non-empty text") stdout.println(" {{Integer}} - whole numbers") stdout.println(" {{Float}} - decimal numbers") stdout.println(" {{Boolean}} - true or false") stdout.println(" {{Date}} - ISO date format") stdout.println(" {{DateTime}} - ISO datetime format") stdout.println(" {{GUID}} - UUID format") stdout.println(" {{Money}} - currency format") // Example: a test printing dynamic values // expected_output.txt would contain: // Record ID: {{GUID}} // Created: {{DateTime}} // Count: {{Integer}} stdout.println("Placeholders match dynamic values in output")
Common mistakes
E50010 — Variables must be declared before use. Using stdout before declaring it is a forward reference. See ek9 -h E50010 for details.
Incorrect:
stdout.println("Dynamic output placeholders:") stdout <- Stdout()
Correct:
stdout <- Stdout() // === DYNAMIC VALUES IN OUTPUT ===
Other ways to ask this
- How do I handle non-deterministic output in EK9 tests?
- What placeholders can I use in expected output files?
- How do I match dynamic values in EK9 test output?
- How do I test output containing dynamic values like dates or GUIDs in EK9?
- What are output placeholders in EK9 tests?
- How do I handle non-deterministic output in EK9 black-box tests?
- How do I use {{Date}} and {{GUID}} in expected output files?
Coming from another language?
Java: Hamcrest matchers or regex in assertions. Python: unittest with regex or mock. Rust: custom test helpers with regex. Go: regex assertions in test functions. Kotlin: custom matchers. EK9: type-aware placeholders in expected output files, validated at test runtime.
Keywords: capture, date, anonymous, format, expected, placeholder, black-box, template, output, timestamp, non-deterministic, match, closure, dynamic, guid, coverage, test