Skip to content

Testing Framework API

API for writing and running USL tests.

Spec Tests

Test Definition

spec MyTests {
  test "description" {
    // test body
    assert condition
  }

  property "property description" {
    forall x in Entity {
      // property to verify
    }
  }
}

Assertions

assert condition
assert_eq(expected, actual)
assert_ne(expected, actual)
expect_error[ErrorCode] { ... }

Running Tests

usl test my-app.usl
usl test --filter "user tests"
usl test --verbose

Generated Tests

USL generates unit tests for: - Entity invariants - Policy rules - State transitions - Service actions

TypeScript

import { runTests } from '@usl-lang/testing';

describe('UserService', () => {
  it('should create user', async () => {
    const user = await createUser('test@example.com');
    expect(user.email).toBe('test@example.com');
  });
});

Rust

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_create_user() {
        let user = create_user("test@example.com");
        assert_eq!(user.email, "test@example.com");
    }
}

Back to Index