January 2019
Beginner to intermediate
554 pages
13h 31m
English
As we stated previously, Rust expects all integration tests to live in the tests/ directory. Files within the tests/ directory are compiled as if they are separate binary crates while using our library under test. For the following example, we'll create a new crate by running cargo new integration_test --lib, with the same function, sum ,as in the previous unit test, but now we have added a tests/ directory, which has an integration test function defined as follows:
// integration_test/tests/sum.rsuse integration_test::sum;#[test]fn sum_test() { assert_eq!(sum(6, 8), 14); }
We first bring the function sum in scope. Second, we have a function, sum_test , that calls sum and asserts on the return value. When we try to ...
Read now
Unlock full access