pub struct TestEnvBuilder { /* private fields */ }Expand description
测试环境构建器
提供流式 API 构建测试环境,支持配置、生命周期钩子和多服务设置。
Implementations§
Source§impl TestEnvBuilder
impl TestEnvBuilder
Sourcepub fn name(self, name: impl Into<String>) -> Self
pub fn name(self, name: impl Into<String>) -> Self
设置环境名称
§Examples
use wae_testing::TestEnvBuilder;
let env = TestEnvBuilder::new().name("my_test_env").build();Sourcepub fn with_logging(self, enable: bool) -> Self
pub fn with_logging(self, enable: bool) -> Self
启用日志
§Examples
use wae_testing::TestEnvBuilder;
let env = TestEnvBuilder::new().with_logging(false).build();Sourcepub fn with_tracing(self, enable: bool) -> Self
pub fn with_tracing(self, enable: bool) -> Self
启用追踪
§Examples
use wae_testing::TestEnvBuilder;
let env = TestEnvBuilder::new().with_tracing(true).build();Sourcepub fn timeout(self, timeout: Duration) -> Self
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();Sourcepub fn custom(self, key: impl Into<String>, value: impl Into<String>) -> Self
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();Sourcepub fn with_lifecycle_hook<H>(self, hook: H) -> Selfwhere
H: TestLifecycleHook + 'static,
pub fn with_lifecycle_hook<H>(self, hook: H) -> Selfwhere
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();Sourcepub fn with_async_lifecycle_hook<H>(self, hook: H) -> Selfwhere
H: AsyncTestLifecycleHook + 'static,
pub fn with_async_lifecycle_hook<H>(self, hook: H) -> Selfwhere
H: AsyncTestLifecycleHook + 'static,
添加异步生命周期钩子
Sourcepub fn with_service(self, service: TestServiceConfig) -> Self
pub fn with_service(self, service: TestServiceConfig) -> Self
添加测试服务配置
向构建器中添加一个服务配置,构建时会自动注册到测试环境。
§Examples
use wae_testing::{TestEnvBuilder, TestServiceConfig};
let env = TestEnvBuilder::new().with_service(TestServiceConfig::new("database")).build();Sourcepub fn with_services<I>(self, services: I) -> Selfwhere
I: IntoIterator<Item = TestServiceConfig>,
pub fn with_services<I>(self, services: I) -> Selfwhere
I: IntoIterator<Item = TestServiceConfig>,
批量添加测试服务配置
向构建器中添加多个服务配置。
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TestEnvBuilder
impl !RefUnwindSafe for TestEnvBuilder
impl Send for TestEnvBuilder
impl Sync for TestEnvBuilder
impl Unpin for TestEnvBuilder
impl UnsafeUnpin for TestEnvBuilder
impl !UnwindSafe for TestEnvBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more