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测试

Download history 42/week @ 2024-05-02 52/week @ 2024-05-09 54/week @ 2024-05-16 46/week @ 2024-05-23 95/week @ 2024-05-30 125/week @ 2024-06-06 164/week @ 2024-06-13 222/week @ 2024-06-20 104/week @ 2024-06-27 114/week @ 2024-07-04 309/week @ 2024-07-11 311/week @ 2024-07-18 405/week @ 2024-07-25 340/week @ 2024-08-01 241/week @ 2024-08-08 179/week @ 2024-08-15

每月下载量 1,217
用于 7 crates

MIT/Apache 许可

15KB
285 代码行

goldie

Crates.io Version Docs.rs Latest Build Status

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-APACHELICENSE-MIT

依赖项

~1.4–2.3MB
~47K SLoC