How-To: Testing Integration
How-To: Testing Integration
Section titled “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
Section titled “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:skipfn calculate_total(subtotal: int, tax: int) to int { return subtotal + tax}
@testfn test_calculate_total() to Unit { let result = calculate_total(100, 10) assert(result == 110)}Testing Result Returns
Section titled “Testing Result Returns”When testing functions that return Result[T, E], you typically use match to assert the correct execution branch.
// vox:skip@testfn 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 }}Testing Asynchronous Workflows
Section titled “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@testfn 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) }}Running Tests
Section titled “Running Tests”Execute all tests in the workspace {
vox testExecute tests targeting a specific module:
vox test src/domain/tasks.voxYou can view the specific failures via standard error stack traces emitted by the V0.3 compiler pipeline.