Skip to content

How-To: Testing Integration

Testing in Vox focuses on unit tests and bounded integration tests using the @test decorator (see How-To: Unit Testing for basic unit test structure). Note that the legacy @mock and @fixture features have been removed or placed into aspirational scope for v0.3.

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

fn calculate_total(subtotal: int, tax: int) to int {
return subtotal + tax
}
@test
fn test_calculate_total() to Unit {
let result = calculate_total(100, 10)
assert(result is 110)
}

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

table Task {
title: str
owner: str
}
@test
fn test_database_insert_validation() to 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
}
}

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.

workflow process_order(customer: str, amount: int) to Result[str] {
if amount <= 0 {
return Error("Invalid amount")
}
return Ok("tx_" + customer)
}
@test
fn test_order_workflow() to Unit {
// Run the workflow natively
let result = process_order("alice", 500)
match result {
Ok(tx) => assert(len(tx) > 0)
Error(_) => assert(false)
}
}

Execute all tests in the workspace {

Terminal window
vox test

Execute tests targeting a specific module:

Terminal window
vox test src/domain/tasks.vox

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