| name | rust-testing |
| description | Generate comprehensive Rust tests for cqlsh-rs modules. Use when asked to write tests, add test coverage, generate unit tests, create integration tests, or improve test coverage for Rust code. Orchestrates test creation following project conventions, cargo test patterns, and the cqlsh-rs testing strategy. |
Rust Test Generator
Generate comprehensive, idiomatic Rust tests for the cqlsh-rs project following the testing strategy defined in docs/plans/10-testing-strategy.md.
Before Writing Tests
- Read the source file being tested
- Read
docs/plans/10-testing-strategy.md for project testing conventions
- Check existing tests in the module and
tests/ directory for patterns
- Identify the testing layer (unit, integration, or CLI)
Testing Layers
Layer 1: Unit Tests (inline in modules)
Place unit tests in the same file as the code they test:
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_function_name_scenario() {
let input = ...;
let result = function_name(input);
assert_eq!(result, expected);
}
}
Naming convention: test_{function}_{scenario} or test_{function}_{input}_{expected}
Layer 2: Integration Tests (tests/ directory)
Place integration tests in tests/ directory:
use cqlsh_rs::driver::*;
#[tokio::test]
async fn test_connection_to_cassandra() {
}
Layer 3: CLI Tests (tests/ directory)
Test the binary itself using assert_cmd:
use assert_cmd::Command;
#[test]
fn test_version_flag() {
Command::cargo_bin("cqlsh-rs")
.unwrap()
.arg("--version")
.assert()
.success()
.stdout(predicates::str::contains(env!("CARGO_PKG_VERSION")));
}
Coverage Scope
For each function or module, generate tests covering:
- Happy path — Valid inputs producing expected outputs
- Edge cases — Empty inputs, boundary values, maximum sizes
- Error conditions — Invalid inputs, missing data, connection failures
- Compatibility — Behavior matching Python cqlsh (reference the compatibility matrix)
Test Patterns for cqlsh-rs
Configuration Parsing Tests
#[test]
fn test_cqlshrc_missing_file_uses_defaults() {
let config = CqlshConfig::load(Path::new("/nonexistent"));
assert_eq!(config.connection.timeout, Duration::from_secs(10));
}
#[test]
fn test_cqlshrc_precedence_cli_over_config() {
}
CQL Parsing Tests
#[test]
fn test_parse_select_simple() {
let stmt = parse("SELECT * FROM users;");
assert!(matches!(stmt, Statement::Select { .. }));
}
#[test]
fn test_parse_semicolon_in_string_literal() {
let stmt = parse("INSERT INTO t (a) VALUES ('hello;world');");
assert_eq!(count_statements(&stmt), 1);
}
Async/Driver Tests
#[tokio::test]
async fn test_query_returns_rows() {
let session = test_session().await;
let rows = session.query("SELECT key FROM system.local", &[]).await.unwrap();
assert!(!rows.is_empty());
}
Snapshot Tests (with insta)
#[test]
fn test_describe_keyspace_output() {
let output = format_describe_keyspace(&keyspace);
insta::assert_snapshot!(output);
}
Property Tests (with proptest)
proptest! {
#[test]
fn test_roundtrip_cql_value(value: CqlValue) {
let formatted = format_value(&value);
let parsed = parse_value(&formatted);
prop_assert_eq!(value, parsed);
}
}
Running Tests
CI-equivalent command (always run this before pushing)
The CI pipeline sets RUSTFLAGS="-Dwarnings" globally, which treats all Rust warnings as compilation errors. Always verify locally with the same flags:
RUSTFLAGS="-Dwarnings" cargo test --all-targets --all-features 2>&1
Standard commands
cargo test
cargo test --lib parser::tests
cargo test --test integration_driver
cargo test --test cli_basic
cargo test -- --nocapture
cargo tarpaulin --out html
Validation Checklist
After generating tests, verify: