TestContext

Struct TestContext 

Source
pub struct TestContext {
    pub result: TestResult,
    pub step_stack: Vec<StepResult>,
    pub writer: AllureWriter,
}
Expand description

Test context holding the current test result and step stack.

Fields§

§result: TestResult

The current test result being built.

§step_stack: Vec<StepResult>

Stack of active steps (for nested steps).

§writer: AllureWriter

The writer for this context.

Implementations§

Source§

impl TestContext

Source

pub fn new(name: impl Into<String>, full_name: impl Into<String>) -> TestContext

Creates a new test context.

Source

pub fn add_label(&mut self, name: impl Into<String>, value: impl Into<String>)

Adds a label to the current test.

Source

pub fn add_label_name(&mut self, name: LabelName, value: impl Into<String>)

Adds a label using a reserved name.

Adds a link to the current test.

Source

pub fn add_parameter( &mut self, name: impl Into<String>, value: impl Into<String>, )

Adds a parameter to the current test or step.

Source

pub fn add_parameter_struct(&mut self, parameter: Parameter)

Adds a parameter with custom options (hidden/masked/excluded).

Source

pub fn add_attachment(&mut self, attachment: Attachment)

Adds an attachment to the current test or step.

Source

pub fn start_step(&mut self, name: impl Into<String>)

Starts a new step.

Source

pub fn finish_step( &mut self, status: Status, message: Option<String>, trace: Option<String>, )

Finishes the current step with the given status.

Source

pub fn compute_history_id(&mut self)

Computes and sets the history ID based on the full name and parameters.

Source

pub fn finish( &mut self, status: Status, message: Option<String>, trace: Option<String>, )

Finishes the test with the given status and writes the result.

Source

pub fn attach_text(&mut self, name: impl Into<String>, content: impl AsRef<str>)

Creates a text attachment.

Source

pub fn attach_json<T>(&mut self, name: impl Into<String>, value: &T)
where T: Serialize,

Creates a JSON attachment.

Source

pub fn attach_binary( &mut self, name: impl Into<String>, content: &[u8], content_type: ContentType, )

Creates a binary attachment.

Source

pub fn attach_file( &mut self, name: impl Into<String>, path: impl AsRef<Path>, content_type: Option<ContentType>, )

Attaches a file from the filesystem.

Trait Implementations§

Source§

impl Debug for TestContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

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> Same for T

Source§

type Output = T

Should always be Self
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.