Skip to main content

test

Macro test 

Source
test!() { /* proc-macro */ }
Expand description

Define an individual test case with a descriptive name

Creates a test function with optional TestDatabase parameter. The test name is displayed in failure output for easy identification.

§Examples

§Async test with database

test!("creates a user", async fn(db: TestDatabase) {
    let user = CreateUserAction::new().execute("test@example.com").await.unwrap();
    expect!(user.email).to_equal("test@example.com".to_string());
});

§Async test without database

test!("calculates sum", async fn() {
    let result = calculate_sum(1, 2).await;
    expect!(result).to_equal(3);
});

§Sync test

test!("adds numbers", fn() {
    expect!(1 + 1).to_equal(2);
});

On failure, the test name is shown:

Test: "creates a user"
  at src/actions/user_action.rs:25

  expect!(actual).to_equal(expected)

  Expected: "test@example.com"
  Received: "wrong@email.com"