Comprehensive Rust(繁体中文) 202406can then quickly mock: use std::time::Duration; pub trait Pet { fn is_hungry(&self, since_last_meal: Duration) -> bool; } fn test_robot_dog() { let mut mock_dog = MockPet::new(); mock_dog.expect_is_hungry() expect_is_hungry().return_const(true); assert_eq!(mock_dog.is_hungry(Duration::from_secs(10)), true); } • Mockall is the recommended mocking library in Android (AOSP). There are other mocking libraries available other mocking libraries work in a similar fashion as Mockall, meaning that they make it easy to get a mock implementation of a given trait. • Note that mocking is somewhat controversial: mocks allow you to0 码力 | 356 页 | 1.41 MB | 1 年前3
共 1 条
- 1













