"How-To: Testing Integration"

How-To: Testing Integration

Testing in Vox focuses on unit tests and bounded integration tests using the @test decorator. Note that the legacy @mock and @fixture features have been removed or placed into aspirational scope for v0.3.

Structuring a Test

Any function annotated with @test will be executed during a vox test invocation. The assert global built-in is used to evaluate conditions.

// vox:skip
fn calculate_total(subtotal: int, tax: int) -> int {
    return subtotal + tax
}

@test
fn test_calculate_total() -> Unit {
    let result = calculate_total(100, 10)
    assert(result == 110)
}

Testing Result Returns

When testing functions that return Result[T, E], you typically use match to assert the correct execution branch.

// vox:skip
@test
fn test_database_insert_validation() -> Unit {
    let invalid_data = { title: "", owner: "alice" }
    
    // Assuming db.Task.insert has a length requirement on title
    match db.Task.insert(invalid_data) {
        Ok(_) -> assert(false) // Should fail
        Error(_) -> assert(true) // Expected
    }
}

Testing Asynchronous Workflows

Workflows and Activities evaluate sequentially and synchronously from the tester's perspective because the execution context blocks until the workflow concludes or hits a checkpoint limit.

// vox:skip
@test
fn test_order_workflow() -> Unit {
    // Run the workflow natively
    let result = process_order("alice", 500)
    
    match result {
        Ok(tx) -> assert(len(tx) > 0)
        Error(_) -> assert(false)
    }
}

Running Tests

Execute all tests in the workspace {

vox test

Execute tests targeting a specific module:

vox test src/domain/tasks.vox

You can view the specific failures via standard error stack traces emitted by the V0.3 compiler pipeline.