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
  {{Date}}      matches ISO dates
  {{DateTime}}  matches ISO datetimes
  {{GUID}}      matches UUID format
  {{Money}}     matches currency format

EXAMPLE EXPECTED OUTPUT FILE

For a program that prints a GUID and timestamp:

  Record ID: {{GUID}}
  Created: {{DateTime}}
  Items: {{Integer}}
  Active: {{Boolean}}

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?

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: match, timestamp, closure, expected, dynamic, anonymous, output, placeholder, test, guid, capture, format, date, coverage