8 个版本 (4 个重大更新)
0.5.0 | 2024年4月21日 |
---|---|
0.4.3 | 2023年1月8日 |
0.4.2 | 2022年11月15日 |
0.4.1 | 2022年10月3日 |
0.1.0 | 2021年10月2日 |
#73 在 测试
每月下载量 1,217
用于 7 crates
15KB
285 代码行
goldie
Rust 的简单 Golden 文件测试。
goldie::assert!(text);
🚀 入门
将 goldie
添加到项目中作为开发依赖项。
cargo add goldie --dev
在测试函数中使用 goldie::assert!
断言内容。Golden 文件名将根据测试文件和测试函数名自动确定。使用 GOLDIE_UPDATE=true
运行测试以自动更新 Golden 文件。
#[test]
fn example() {
let text = { /* ... run the test ... */ };
// assert that the contents of ./testdata/example.golden
// are equal to `text`
goldie::assert!(text)
}
还支持使用 goldie::assert_template!
模板 Golden 文件。需要提供实现 serde::Serialize
的类型作为上下文以渲染模板。值使用 upon 渲染,例如 {{ value.field }}
。不能使用 GOLDIE_UPDATE=true
自动更新模板 Golden 文件。
#[test]
fn example() {
let text = { /* ... run the test ... */ };
// assert that the contents of ./testdata/example.golden
// are equal to `text` after rendering with `ctx`.
let ctx = upon::value!{ value: "Hello World!" };
goldie::assert_template!(&ctx, text)
}
许可证
本项目根据 MIT 许可证和 Apache 许可证(版本 2.0)的条款进行分发。
有关详细信息,请参阅 LICENSE-APACHE 和 LICENSE-MIT。
依赖项
~1.4–2.3MB
~47K SLoC