#mocking #tdd

funnybot

简单的/直观的mock辅助工具:记录参数,返回预先记录的值

1个不稳定版本

0.1.0 2020年7月20日

#725 in 测试

MIT/Apache

8KB
57

Rust build crates.io badge docs.rs badge

Funnybot

简单的/直观的mock辅助工具:记录参数,返回预先记录的值。

由于记录需要参数,Funnybot的主要任务是在RwLock之后隐藏这一点,并且通常是从手动mock中提取冗余信息。

示例


struct MockRepository<'a> {
    // funnybot-instance to hold recorded arguments (here: `String`) and return-values (here: list of String)
    pub group_members: FunnyBot<'a, String, Vec<String>>
}

impl<'a> Repository for MockRepository<'a> {
    async fn list_group_members(&self, group_id: &str) -> Vec<String> {
        self.group_members.call(group_id.to_owned())
    }   
}

#[test]
fn test_something() {
    let mock_repository = MockRepositry {
        group_members: FunnyBot::repeat(vec!["stan", "kyle", "eric", "kenny"])
    };

    let subject = Subject::new(&mock_repository);
  
    let actual = subject.my_function();
  
    assert_eq!(mock_repository.group_members.args(), vec["main-characters"]);
    assert_eq!(actual,);
}

无运行时依赖