-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Hi,
as I understand it in all the examples in the README, the code in main() was using some murf-code. e.g. let (handle, mock) = MyStruct::mock_with_handle();. Is it possible to use murf without changing my application code. Only in the test code? e.g. here is a "real world" example where one function takes a long time to run. I'd like replace it during testing so the test would run faster:
pub fn add(left: u64, right: u64) -> u64 {
long();
left + right
}
pub fn long() {
std::thread::sleep(std::time::Duration::from_secs(20));
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
// replace the long() function to return immediately
let result = add(2, 2);
assert_eq!(result, 4);
}
}And another version of the code, this time using a struct:
#![allow(dead_code)]
struct Rectangle {
length: u32,
width: u32,
}
impl Rectangle {
fn area(&self) -> u32 {
self.long();
self.width * self.length
}
}
impl Rectangle {
fn long(&self) {
std::thread::sleep(std::time::Duration::from_secs(20));
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() {
let r = Rectangle { length: 2, width: 3};
assert_eq!(r.area(), 6);
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels