Crates.io | gilder |
lib.rs | gilder |
version | 0.1.4 |
source | src |
created_at | 2023-08-11 10:06:56.582052 |
updated_at | 2024-05-02 09:10:34.532834 |
description | Golden testing library |
homepage | |
repository | https://github.com/carrotflakes/gilder |
max_upload_size | |
id | 941754 |
size | 19,346 |
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.
[dev-dependencies]
gilder = "0.1"
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.
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.
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.
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)
Licensed under either of
at your option.