testing
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTesting Guide
测试指南
Test Types & When to Use
测试类型及适用场景
| Type | Location | Use Case |
|---|---|---|
| | SQL compatibility. Preferred for new tests |
TCL | | Legacy SQL compat (being phased out) |
| Rust integration | | Regression tests, complex scenarios |
| Fuzz | | Complex features, edge case discovery |
Note: TCL tests are being phased out in favor of testing/runner. The format allows the same test cases to run against multiple backends (CLI, Rust bindings, etc.).
.sqltest| 类型 | 位置 | 适用场景 |
|---|---|---|
| | SQL兼容性测试。优先用于新测试 |
TCL | | 遗留SQL兼容性测试(逐步淘汰中) |
| Rust集成测试 | | 回归测试、复杂场景测试 |
| 模糊测试 | | 复杂功能、边缘场景发现 |
注意: TCL测试正逐步被testing/runner替代。格式允许相同的测试用例在多个后端(CLI、Rust绑定等)上运行。
.sqltestRunning Tests
运行测试
bash
undefinedbash
undefinedMain test suite (TCL compat, sqlite3 compat, Python wrappers)
主测试套件(TCL兼容性、sqlite3兼容性、Python包装器)
make test
make test
Single TCL test
单个TCL测试
make test-single TEST=select.test
make test-single TEST=select.test
SQL test runner
SQL测试运行器
make -C testing/runner run-cli
make -C testing/runner run-cli
Rust unit/integration tests (full workspace)
Rust单元/集成测试(完整工作区)
cargo test
undefinedcargo test
undefinedWriting Tests
编写测试
.sqltest (Preferred)
.sqltest(推荐)
@database :default:
test example-addition {
SELECT 1 + 1;
}
expect {
2
}
test example-multiple-rows {
SELECT id, name FROM users WHERE id < 3;
}
expect {
1|alice
2|bob
}Location:
testing/runner/tests/*.sqltestYou must start converting TCL tests with the command from the test runner (e.g ). It is not always accurate, but it will convert most of the tests. If some conversion emits a warning you will have to write by hand whatever is missing from it (e.g unroll a for each loop by hand). Then you need to verify the tests work by running them with , and adjust their output if something was wrong with the conversion. Also, we use harcoded databases in TCL, but with we generate the database with a different seed, so you will probably need to change the expected test result to match the new database query output. Avoid changing the SQL statements from the test, just change the expected result
convertcargo run -- convert <TCL_test_path> -o <out_dir>make -C testing/runner run-rust.sqltest@database :default:
test example-addition {
SELECT 1 + 1;
}
expect {
2
}
test example-multiple-rows {
SELECT id, name FROM users WHERE id < 3;
}
expect {
1|alice
2|bob
}位置:
testing/runner/tests/*.sqltest你必须使用测试运行器的命令来转换TCL测试(例如)。转换并不总是完全准确,但它会转换大部分测试内容。如果转换过程中出现警告,你需要手动补充缺失的部分(例如手动展开for each循环)。然后你需要通过运行来验证测试是否正常工作,如果转换后的输出有问题,需要调整预期结果。另外,我们在TCL中使用硬编码的数据库,但在中我们使用不同的种子生成数据库,因此你可能需要修改测试的预期结果以匹配新的数据库查询输出。避免修改测试中的SQL语句,只需调整预期结果即可。
convertcargo run -- convert <TCL测试路径> -o <输出目录>make -C testing/runner run-rust.sqltestTCL
TCL测试
tcl
do_execsql_test_on_specific_db {:memory:} test-name {
SELECT 1 + 1;
} {2}Location:
testing/*.testtcl
do_execsql_test_on_specific_db {:memory:} test-name {
SELECT 1 + 1;
} {2}位置:
testing/*.testRust Integration
Rust集成测试
rust
// tests/integration/test_foo.rs
#[test]
fn test_something() {
let conn = Connection::open_in_memory().unwrap();
// ...
}rust
// tests/integration/test_foo.rs
#[test]
fn test_something() {
let conn = Connection::open_in_memory().unwrap();
// ...
}Key Rules
关键规则
- Every functional change needs a test
- Test must fail without change, pass with it
- Prefer in-memory DBs: (sqltest) or
:memory:(TCL){:memory:} - Don't invent new test formats. Follow existing patterns
- Write tests first when possible
- 每个功能变更都需要对应测试
- 测试在没有变更时必须失败,变更后必须通过
- 优先使用内存数据库:(sqltest)或
:memory:(TCL){:memory:} - 不要创建新的测试格式,遵循现有模式
- 尽可能先编写测试
Test Database Schema
测试数据库 Schema
testing/system/testing.dbusersproductstesting/system/testing.dbusersproductsLogging During Tests
测试期间的日志记录
bash
RUST_LOG=none,turso_core=trace make testOutput: . Warning: very verbose.
testing/system/test.logbash
RUST_LOG=none,turso_core=trace make test输出:。注意:内容非常详细。
testing/system/test.log