Follow these steps to learn more about creating a test suite for your Rust projects:
- Once created, a library project already contains a very simple test (probably to encourage you to write more). The cfg(test) and test attributes tell cargo (the test runner) how to deal with the module:
#[cfg(test)]mod tests { #[test] fn it_works() { assert_eq!(2 + 2, 4); }}
- Before we add further tests, let's add a subject that needs testing. In this case, let's use something interesting: a singly linked list from our other book (Hands-On Data Structures and Algorithms with Rust) made generic. It consists of three parts. First is a node type:
#[derive(Clone)]struct Node<T> where T: Sized + Clone { value: T, next: Link<T>,}impl<T> Node<T> ...