DSCC
home / cookbook / 02-test-generation

02 · Test Generation

A pure function without tests is the friendliest target for an AI-written test suite: inputs and outputs are observable, no mocks required. This case asks DSCC to read one file and create a table-driven test file that covers happy path, edge cases, and error cases.

Capability demonstrated

Setup

Inside a Rust project (e.g. a fresh cargo new --lib util_demo), create a target function:

cat > src/utils.rs <<'RS'
use std::time::Duration;

pub fn parse_duration(s: &str) -> Option<Duration> {
    let s = s.trim();
    if s.is_empty() { return None; }
    let (num, unit) = s.split_at(s.len() - 1);
    let n: u64 = num.parse().ok()?;
    match unit {
        "s" => Some(Duration::from_secs(n)),
        "m" => Some(Duration::from_secs(n * 60)),
        "h" => Some(Duration::from_secs(n * 3600)),
        _ => None,
    }
}
RS

Then expose it from src/lib.rs:

echo 'pub mod utils;' >> src/lib.rs

Run command

dscc --model claude-sonnet-4-6 \
  --permission-mode workspace-write \
  prompt "$(cat docs/cookbook/02-test-generation/PROMPT.md)"

A live run against doubao-seed-2.0-code is captured at report_dscc.md; the generated test file is preserved at generated_utils_test.rs.

Note: when you run it unattended, use --permission-mode danger-full-access (or install a PreToolUse hook that auto-approves cargo *), because the model will want to shell out to cargo test for self-verification.

Expected behavior

The model should typically:

  1. read_file on src/utils.rs.
  2. Possibly glob_search for Cargo.toml / existing tests.
  3. write_file on tests/utils_test.rs with a #[test]-based table.

No edits to src/utils.rs.

Verification