Skip to main content

Module testing

Module testing 

Source
Expand description

Testing utilities for Ferro framework

Provides Jest-like testing helpers including:

  • expect! macro for fluent assertions with clear expected/received output
  • describe! and test! macros for test organization
  • TestDatabase for isolated database tests
  • TestContainer for dependency injection in tests
  • TestClient and TestResponse for HTTP testing
  • Factory and Fake for generating test data

§Example

use crate::{describe, test, expect};
use crate::testing::{TestDatabase, TestClient, Fake, Factory};

describe!("UserService", {
    test!("creates a user", async fn(db: TestDatabase) {
        let service = UserService::new();
        let user = service.create(Fake::email()).await.unwrap();

        expect!(user.email).to_contain("@");
    });

    test!("lists users via API", async fn(db: TestDatabase) {
        let client = TestClient::new();

        let response = client.get("/api/users").send().await;

        response
            .assert_ok()
            .assert_json_has("users");
    });
});

Re-exports§

pub use crate::container::testing::TestContainer;
pub use crate::container::testing::TestContainerGuard;
pub use crate::database::testing::TestDatabase;

Structs§

Expect
The main Expect wrapper for fluent assertions
FactoryBuilder
Builder for creating model instances with customizations
FactoryTraits
Collection of named traits (states) for a factory
Fake
Helper for generating fake data
Sequence
Convenience function to create a sequence of unique items
TestClient
HTTP test client for making requests to the application
TestRequestBuilder
Builder for constructing test requests
TestResponse
Test response with assertion methods

Traits§

DatabaseFactory
Trait for models that can be persisted to database via factories
Factory
Trait for models that can be created via factories

Functions§

set_current_test_name
Set the current test name (called by test! macro)