Skip to content

Mock traits #35

@asomers

Description

@asomers

Mocktopus is very handy for mocking free functions. But when mocking structs, it requires a real copy of the struct to be instantiated. That's not always easy or possible in test environments. That's why most mocking libraries work in terms of traits instead. It would be great if Mocktopus could provide a macro that would instantiate a trait and mock all of its methods. Something like this:

#[mockable]
pub trait A {
    fn foo(&self) -> u32;
}
mock!{AMock, A}

The mock macro could expand to this:

#[derive(Default)]
pub struct AMock {}
#[mockable]
impl AMock {
    fn foo(&self) -> u32 {
        unimplemented!()
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions