Skip to main content

Testing

Voltaire uses a strict TDD approach. Tests are first-class citizens, never stubs or placeholders.

Core Principle

Every line correct. No stubs, no commented tests.If a test exists, it passes. If it doesn’t pass, fix it or delete it.

Test Organization

Zig Tests

Inline in source files:

TypeScript Tests

Separate test files:

Benchmarks

Running Tests

Zig Tests

TypeScript Tests

TDD Workflow

The Loop

  1. Write failing test
  2. Implement minimal code to pass
  3. Refactor
  4. Run zig build && zig build test
  5. Repeat

Bug Fixing

Always produce a failing test first:
Then fix the implementation. The test stays forever.

Zig Test Patterns

Basic Assertion

Error Testing

Slice Comparison

Debug Output

Memory Testing

TypeScript Test Patterns

Basic Test

Error Testing

Async Testing

Table-Driven Tests

Cross-Validation

Validate against known-good vectors (no external libs):

Test Coverage

Generating Coverage

Coverage Goals

  • Core primitives: 100%
  • Crypto functions: 100%
  • Edge cases: exhaustive
  • Error paths: covered

Fuzz Testing

Zig Fuzz Tests

Running Fuzz Tests

Security Testing

What Security Tests Cover

  • Constant-time comparisons
  • No timing leaks
  • Input validation
  • Memory clearing after sensitive ops
  • Edge case handling

Benchmarks

Zig Benchmarks

TypeScript Benchmarks

Running Benchmarks

Common Mistakes

Avoid these testing anti-patterns:
All of these should either be:
  1. Implemented properly
  2. Deleted entirely