Rust能力养成之(15)集成测试
前言
第一个集成测试
// integration_test/tests/sum.rs
use integration_test::sum;
#[test]
fn sum_test() {
assert_eq!(sum(6, 8), 14);
}
.
├── Cargo.lock
├── Cargo.toml
├── src
│ └── lib.rs
└── tests
└── sum.rs
共享代码(Sharing common code)
// integration_test/tests/common.rs
pub fn setup() {
println!("Setting up fixtures");
}
pub fn teardown() {
println!("Tearing down");
}
// integration_test/tests/sum.rs
use integration_test::sum;
mod common;
use common::{setup, teardown};
#[test]
fn sum_test() {
assert_eq!(sum(6, 8), 14);
}
#[test]
fn test_with_fixture() {
setup();
assert_eq!(sum(7, 14), 21);
teardown();
}
后记
往
期
推
荐
01
02
03
04
05
06
07
08
09
10
11
12
13
14