Skip to content

Golden testing library for Rust

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

carrotflakes/gilder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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

License

Licensed under either of

at your option.

About

Golden testing library for Rust

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages