Update README.md

This commit is contained in:
Víctor Martínez 2025-01-27 13:57:54 +01:00 committed by GitHub
parent 5c8a0a1d51
commit b1e59dae46
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -47,42 +47,6 @@ fn test_generic_type(ctx: &mut MyGenericContext<u32>) {
}
```
with generic types, you can use same type with different values
```rust
use test_context::{test_context, TestContext};
use std::marker::PhantomData;
struct MyGenericContext<T> {
value: u32,
_marker: PhantomData<T>,
}
impl TestContext for MyGenericContext<String> {
fn setup() -> MyGenericContext<String> {
MyGenericContext { value: 1, _marker: PhantomData }
}
}
#[test_context(MyGenericContext<String>)]
#[test]
fn test_generic_type(ctx: &mut MyGenericContext<String>) {
assert_eq!(ctx.value, 1);
}
impl TestContext for MyGenericContext<u32> {
fn setup() -> MyGenericContext<u32> {
MyGenericContext { value: 2, _marker: PhantomData }
}
}
#[test_context(MyGenericContext<u32>)]
#[test]
fn test_generic_type_u32(ctx: &mut MyGenericContext<u32>) {
assert_eq!(ctx.value, 2);
}
```
Alternatively, you can use `async` functions in your test context by using the
`AsyncTestContext`.