4 releases

new 0.1.4 May 2, 2024
0.1.3 Apr 27, 2024
0.1.2 Apr 27, 2024
0.1.1 Aug 20, 2023
0.1.0 Aug 11, 2023

#1314 in Rust patterns

Download history 4/week @ 2024-02-16 19/week @ 2024-02-23 6/week @ 2024-03-01 1/week @ 2024-03-08 1/week @ 2024-03-15 26/week @ 2024-03-29 8/week @ 2024-04-05 347/week @ 2024-04-26

364 downloads per month

MIT/Apache

9KB
139 lines

Gilder

Crates.io

Gilder is an assertion library for lazy folks (also say a golden testing library).

The golden test is a testing method commonly used to detect changes in program output. It ensures that the results remain consistent even when modifying the code.

In a golden test, the program's output is saved in a file known as the golden file to preserve it. During testing, the actual output is compared against the content of the golden file.

Gilder is designed to minimize the implementation cost and provides only one API for usage, which is the assert_golden! macro. It can be used similar to assert_eq! but without the second argument.

Getting Started

  1. Add Gilder as a dependency in your Cargo.toml file:
[dev-dependencies]
gilder = "0.1"
  1. Write a new test using assert_golden! macro:
#[test]
fn my_test() {
    use gilder::assert_golden;

    let target = something_you_want_to_test();
    assert_golden!(target);
}

The argument to assert_golden! must implement the ToString trait to write to the golden file.

  1. Create golden files:

Golden files are generated by running the tests for the first time.

cargo test

A golden file with the .gld extension will be saved in the same directory as the source file containing the test code.

  1. Testing:

When running the tests with the golden files present, the behavior is the same as a regular test.

cargo test

The macro will raise an error if it detects a change in value.

  1. Updating the golden files:

When you change the output of your function, it is necessary to update the golden files accordingly.

To update the golden files, delete the existing ones and rerun the tests.

Copyright (c) 2023 carrotflakes (carrotflakes@gmail.com)

License

Licensed under either of

at your option.

No runtime deps