Skip to content

Testing

Terminal window
# All tests
cargo test
# Specific test
cargo test test_split_mysql
# With output
cargo test -- --nocapture

In-module tests for specific functions:

#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_parse_create_table() {
// ...
}
}

End-to-end tests in tests/:

tests/split_tests.rs
#[test]
fn test_split_mysql_dump() {
let output = Command::new("./target/release/sql-splitter")
.args(["split", "tests/fixtures/mysql.sql", "-o", "output/"])
.output()
.expect("failed to execute");
assert!(output.status.success());
}

Test against real SQL dumps:

Terminal window
make verify-realworld

Located in tests/fixtures/:

tests/fixtures/
├── mysql/
│ ├── simple.sql
│ ├── multi_table.sql
│ └── compressed.sql.gz
├── postgres/
│ ├── simple.sql
│ └── with_copy.sql
├── sqlite/
│ └── simple.sql
└── mssql/
└── simple.sql
  1. Create fixture files in tests/fixtures/
  2. Write unit tests in the module
  3. Write integration test in tests/
  4. Run cargo test
-- tests/fixtures/mysql/my_feature.sql
CREATE TABLE test (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100)
);
INSERT INTO test VALUES (1, 'Alice');
INSERT INTO test VALUES (2, 'Bob');
#[test]
fn test_my_feature() {
let result = my_function("tests/fixtures/mysql/my_feature.sql");
assert!(result.is_ok());
assert_eq!(result.unwrap().table_count, 1);
}
Terminal window
cargo install cargo-tarpaulin
cargo tarpaulin --out Html

Open tarpaulin-report.html to view coverage.