Skip to main content

TestEnvBuilder

Struct TestEnvBuilder 

Source
pub struct TestEnvBuilder { /* private fields */ }
Expand description

测试环境构建器

提供流式 API 构建测试环境,支持配置、生命周期钩子和多服务设置。

Implementations§

Source§

impl TestEnvBuilder

Source

pub fn new() -> Self

创建新的构建器

§Examples
use wae_testing::TestEnvBuilder;

let builder = TestEnvBuilder::new();
Source

pub fn name(self, name: impl Into<String>) -> Self

设置环境名称

§Examples
use wae_testing::TestEnvBuilder;

let env = TestEnvBuilder::new().name("my_test_env").build();
Source

pub fn with_logging(self, enable: bool) -> Self

启用日志

§Examples
use wae_testing::TestEnvBuilder;

let env = TestEnvBuilder::new().with_logging(false).build();
Source

pub fn with_tracing(self, enable: bool) -> Self

启用追踪

§Examples
use wae_testing::TestEnvBuilder;

let env = TestEnvBuilder::new().with_tracing(true).build();
Source

pub fn timeout(self, timeout: Duration) -> Self

设置超时时间

§Examples
use std::time::Duration;
use wae_testing::TestEnvBuilder;

let env = TestEnvBuilder::new().timeout(Duration::from_secs(60)).build();
Source

pub fn custom(self, key: impl Into<String>, value: impl Into<String>) -> Self

添加自定义配置

§Examples
use wae_testing::TestEnvBuilder;

let env = TestEnvBuilder::new().custom("key", "value").build();
Source

pub fn with_lifecycle_hook<H>(self, hook: H) -> Self
where H: TestLifecycleHook + 'static,

添加同步生命周期钩子

§Examples
use wae_testing::{TestEnv, TestEnvBuilder, TestLifecycleHook};

struct MyHook;

impl TestLifecycleHook for MyHook {}

let env = TestEnvBuilder::new().with_lifecycle_hook(MyHook).build();
Source

pub fn with_async_lifecycle_hook<H>(self, hook: H) -> Self
where H: AsyncTestLifecycleHook + 'static,

添加异步生命周期钩子

Source

pub fn with_service(self, service: TestServiceConfig) -> Self

添加测试服务配置

向构建器中添加一个服务配置,构建时会自动注册到测试环境。

§Examples
use wae_testing::{TestEnvBuilder, TestServiceConfig};

let env = TestEnvBuilder::new().with_service(TestServiceConfig::new("database")).build();
Source

pub fn with_services<I>(self, services: I) -> Self

批量添加测试服务配置

向构建器中添加多个服务配置。

Source

pub fn build(self) -> TestEnv

构建测试环境

使用当前配置构建并返回测试环境实例。

§Examples
use wae_testing::TestEnvBuilder;

let env = TestEnvBuilder::new().build();

Trait Implementations§

Source§

impl Default for TestEnvBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.