Testing
Run Tests
Section titled “Run Tests”# All testscargo test
# Specific testcargo test test_split_mysql
# With outputcargo test -- --nocaptureTest Categories
Section titled “Test Categories”Unit Tests
Section titled “Unit Tests”In-module tests for specific functions:
#[cfg(test)]mod tests { use super::*;
#[test] fn test_parse_create_table() { // ... }}Integration Tests
Section titled “Integration Tests”End-to-end tests in tests/:
#[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());}Real-World Verification
Section titled “Real-World Verification”Test against real SQL dumps:
make verify-realworldTest Fixtures
Section titled “Test Fixtures”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.sqlWriting Tests
Section titled “Writing Tests”Test a New Feature
Section titled “Test a New Feature”- Create fixture files in
tests/fixtures/ - Write unit tests in the module
- Write integration test in
tests/ - Run
cargo test
Test Fixture Example
Section titled “Test Fixture Example”-- tests/fixtures/mysql/my_feature.sqlCREATE TABLE test ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100));
INSERT INTO test VALUES (1, 'Alice');INSERT INTO test VALUES (2, 'Bob');Test Code Example
Section titled “Test Code Example”#[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);}Code Coverage
Section titled “Code Coverage”cargo install cargo-tarpaulincargo tarpaulin --out HtmlOpen tarpaulin-report.html to view coverage.