Skip to content

Instantly share code, notes, and snippets.

@hoony-o-1
Last active December 11, 2019 12:53
Show Gist options
  • Save hoony-o-1/ce1819f1f9fbb7a3daa2deaf4fdc17cc to your computer and use it in GitHub Desktop.
Save hoony-o-1/ce1819f1f9fbb7a3daa2deaf4fdc17cc to your computer and use it in GitHub Desktop.
unit test & integration test in Rust
// tests/integration_test.rs
use adder;
mod common;
#[test]
fn add_two_test() {
common::setup();
assert_eq!(adder::add_two(2), 4);
}
// src/lib.rs
pub fn add_two(a: i32) -> i32 {
a + 2
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn add_two_unit_test() {
assert_eq!(add_two(2), 4);
}
}
// tests/common/mod.rs
fn add_two_unit_test() {
assert!(add_two(2) == 4);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment