Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to mockall #[cfg_attr(test, automock)] on trait #87

Open
SpAndrea117 opened this issue May 23, 2024 · 1 comment
Open

Switch to mockall #[cfg_attr(test, automock)] on trait #87

SpAndrea117 opened this issue May 23, 2024 · 1 comment

Comments

@SpAndrea117
Copy link

Why this crate implements a proper way of mocking the protocol? It would be much more flexible, for unit test purposes, to provide to the end user the possibility to describe the trait mocked method behaviour using the mockall crate pattern

@SpAndrea117
Copy link
Author

SpAndrea117 commented May 31, 2024

For unit test purposes, it would make sense to add also a method named read_regs to I2CRegisterMap? It would make easy to perform comparison after i2c writing operations.
Maybe something like this could make sense

/// Read several registers starting from the given offset till offset+len
pub fn read_regs(&mut self, offset: usize, len: usize) -> Vec<u8> {
    println!("READ | 0x{:X} : {:?}", offset, self.registers[offset+1..offset+len]);
    self.registers[offset+1..offset+len].to_vec()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant