Basic Testing Examples
This section provides practical examples of testing in Phlow, showing different scenarios and their expected outputs.
String Concatenation Testโ
Here's a simple example testing string concatenation:
string-test.phlow
name: String Test
version: 1.0.0
description: Testing string operations
tests:
- main:
name: "John"
payload: "Hello"
assert_eq: "Hello John"
- main:
name: "Alice"
payload: "Hi"
assert_eq: "Hi Alice"
- main:
name: "Bob"
payload: "Hey"
assert_eq: "Hey Bob"
steps:
- payload: !phs `${payload} ${main.name}`
Running the Testโ
phlow --test string-test.phlow
Expected Outputโ
[2025-07-15T00:11:48Z INFO phlow::loader] Downloading modules...
[2025-07-15T00:11:48Z INFO phlow::loader] All modules downloaded and extracted successfully
๐งช Running 3 test(s)...
Test 1: โ
PASSED - Expected and got: Hello John
Test 2: โ
PASSED - Expected and got: Hi Alice
Test 3: โ
PASSED - Expected and got: Hey Bob
๐ Test Results:
Total: 3
Passed: 3 โ
Failed: 0 โ
๐ All tests passed!
Basic Math Testโ
Here's an example testing basic arithmetic operations:
math-test.phlow
name: Basic Math Test
version: 1.0.0
description: Testing basic arithmetic operations
tests:
- main:
x: 10
y: 20
payload: 5
assert: !phs payload == 35
- main:
x: 0
y: 0
payload: 100
assert: !phs payload == 100
- main:
x: -5
y: 5
payload: 10
assert: !phs payload > 0
steps:
- payload: !phs main.x + main.y + payload
Running the Testโ
phlow --test math-test.phlow
Expected Outputโ
[2025-07-15T00:07:55Z INFO phlow::loader] Downloading modules...
[2025-07-15T00:07:55Z INFO phlow::loader] All modules downloaded and extracted successfully
๐งช Running 3 test(s)...
Test 1: โ
PASSED - Assertion passed: {{ payload == 35 }}
Test 2: โ
PASSED - Assertion passed: {{ payload == 100 }}
Test 3: โ
PASSED - Assertion passed: {{ payload > 0 }}
๐ Test Results:
Total: 3
Passed: 3 โ
Failed: 0 โ
๐ All tests passed!
Test with Failuresโ
Here's an example showing what happens when tests fail:
fail-test.phlow
name: Failing Test Example
version: 1.0.0
description: Example showing test failures
tests:
- main:
name: "John"
payload: "Hello"
assert_eq: "Hello John"
- main:
name: "Alice"
payload: "Hi"
assert_eq: "Wrong expectation"
- main:
name: "Bob"
payload: "Hey"
assert: !phs payload == "Something else"
steps:
- payload: !phs `${payload} ${main.name}`
Running the Testโ
phlow --test fail-test.phlow
Expected Outputโ
[2025-07-15T00:11:59Z INFO phlow::loader] Downloading modules...
[2025-07-15T00:11:59Z INFO phlow::loader] All modules downloaded and extracted successfully
๐งช Running 3 test(s)...
Test 1: โ
PASSED - Expected and got: Hello John
Test 2: โ FAILED - Expected Wrong expectation, got Hi Alice
Test 3: โ FAILED - Assertion failed: {{ payload == "Something else" }}
๐ Test Results:
Total: 3
Passed: 1 โ
Failed: 2 โ
โ Some tests failed!
Different Assertion Typesโ
Using assert
(Expression-based)โ
tests:
- main:
value: 42
payload: 100
assert: !phs payload > main.value
- main:
name: "test"
payload: "test string"
assert: !phs payload.includes(main.name)
- main:
items: [1, 2, 3]
payload: 3
assert: !phs payload == main.items.length
Using assert_eq
(Direct comparison)โ
tests:
- main:
multiplier: 2
payload: 10
assert_eq: 20
- main:
prefix: "Hello"
payload: "World"
assert_eq: "Hello World"
steps:
- payload: !phs main.multiplier * payload
- payload: !phs `${main.prefix} ${payload}`
Testing Conditional Logicโ
conditional-test.phlow
name: Conditional Logic Test
version: 1.0.0
description: Testing conditional logic
tests:
- main:
age: 25
payload: null
assert: !phs payload == "Adult"
- main:
age: 16
payload: null
assert: !phs payload == "Minor"
- main:
age: 18
payload: null
assert: !phs payload == "Adult"
steps:
- assert: !phs main.age >= 18
then:
payload: "Adult"
else:
payload: "Minor"
This example tests different age values and ensures the conditional logic works correctly for determining adult vs minor status.
Testing with Initial Payloadโ
payload-test.phlow
name: Payload Test
version: 1.0.0
description: Testing with initial payload values
tests:
- main:
factor: 2
payload: 10
assert: !phs payload == 20
- main:
factor: 0
payload: 100
assert: !phs payload == 0
- main:
factor: -1
payload: 5
assert: !phs payload == -5
steps:
- payload: !phs main.factor * payload
This example shows how to test workflows that start with an initial payload value and transform it through the steps.
Key Pointsโ
assert_eq
is better for exact value comparisonsassert
is better for complex conditions and expressions- Test names should be descriptive of what they're testing
- Error messages clearly show what was expected vs what was received
- Exit codes indicate success (0) or failure (non-zero) for CI/CD integration