Skip to main content

TestEnv

Struct TestEnv 

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

测试环境管理器

Implementations§

Source§

impl TestEnv

Source

pub fn new(config: TestEnvConfig) -> Self

创建新的测试环境

Source

pub fn default_env() -> Self

创建默认测试环境

Source

pub fn setup(&self) -> TestingResult<()>

初始化测试环境

Source

pub fn teardown(&self) -> TestingResult<()>

清理测试环境

Source

pub fn state(&self) -> TestEnvState

获取环境状态

Source

pub fn on_cleanup<F>(&self, handler: F)
where F: Fn() + Send + Sync + 'static,

注册清理函数

Source

pub fn set<T: 'static + Send + Sync>(&self, key: &str, value: T)

存储数据

Source

pub fn get<T: 'static + Clone>(&self, key: &str) -> Option<T>

获取数据

Source

pub fn config(&self) -> &TestEnvConfig

获取配置

Source

pub async fn with_fixture<F, R>(&self, fixture: F) -> TestingResult<R>
where F: FnOnce() -> TestingResult<R>,

使用 fixture 运行测试

Source

pub async fn run_test<F, Fut>(&self, test: F) -> TestingResult<()>
where F: FnOnce() -> Fut, Fut: Future<Output = TestingResult<()>>,

运行异步测试

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.