All Projects → aaronabramov → K9

aaronabramov / K9

Licence: mit
Rust testing library

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to K9

Verify
BDD Assertions for PHPUnit and Codeception
Stars: ✭ 127 (-34.54%)
Mutual labels:  assertions
Go Testdeep
Extremely flexible golang deep comparison, extends the go testing package, tests HTTP APIs and provides tests suite
Stars: ✭ 137 (-29.38%)
Mutual labels:  assertions
Expekt
BDD assertion library for Kotlin
Stars: ✭ 163 (-15.98%)
Mutual labels:  assertions
Nightwatch Custom Commands Assertions
Nightwatch.js custom commands and assertions
Stars: ✭ 131 (-32.47%)
Mutual labels:  assertions
Swaggerassertions
Assert your API requests and responses match with your swagger definition
Stars: ✭ 137 (-29.38%)
Mutual labels:  assertions
Zunit
A powerful testing framework for ZSH projects
Stars: ✭ 140 (-27.84%)
Mutual labels:  assertions
Expect More
Curried Type Testing library, and Test Matchers for Jest
Stars: ✭ 124 (-36.08%)
Mutual labels:  assertions
Fluentassertions
A very extensive set of extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style unit tests. Targets .NET Framework 4.7, .NET Core 2.1 and 3.0, as well as .NET Standard 2.0 and 2.1. Supports the unit test frameworks MSTest2, NUnit3, XUnit2, MSpec, and NSpec3.
Stars: ✭ 2,449 (+1162.37%)
Mutual labels:  assertions
Catch Exception
Stars: ✭ 137 (-29.38%)
Mutual labels:  assertions
Assertj Core
AssertJ is a library providing easy to use rich typed assertions
Stars: ✭ 2,085 (+974.74%)
Mutual labels:  assertions
Tf
✔️ tf is a microframework for parameterized testing of functions and HTTP in Go.
Stars: ✭ 133 (-31.44%)
Mutual labels:  assertions
Supertest
The motivation with this module is to provide a high-level abstraction for testing HTTP, while still allowing you to drop down to the lower-level API provided by superagent.
Stars: ✭ 11,712 (+5937.11%)
Mutual labels:  assertions
Property Validator
✅ Easy property validation for JavaScript, Node and Express.
Stars: ✭ 153 (-21.13%)
Mutual labels:  assertions
Chai Webdriver
Build more expressive integration tests with webdriver sugar for chai.js
Stars: ✭ 128 (-34.02%)
Mutual labels:  assertions
Checkmate
Fast and versatile argument checks
Stars: ✭ 174 (-10.31%)
Mutual labels:  assertions
Scott
Never debug a test again: Detailed failure reports and hassle free assertions for Java tests - Power Asserts for Java
Stars: ✭ 125 (-35.57%)
Mutual labels:  assertions
Postman Bdd
A BDD test framework for Postman and Newman
Stars: ✭ 139 (-28.35%)
Mutual labels:  assertions
Testify
A toolkit with common assertions and mocks that plays nicely with the standard library
Stars: ✭ 14,996 (+7629.9%)
Mutual labels:  assertions
Redux Actions Assertions
Simplify testing of redux action and async action creators
Stars: ✭ 177 (-8.76%)
Mutual labels:  assertions
Should.js
BDD style assertions for node.js -- test framework agnostic
Stars: ✭ 1,908 (+883.51%)
Mutual labels:  assertions

K9 - Rust Testing Library

Crates.io Docs.rs Rust CI

k9_header

Snapshot testing + better assertions

Available test macros

  • snapshot
  • assert_equal
  • assert_greater_than
  • assert_greater_than_or_equal
  • assert_lesser_than
  • assert_lesser_than_or_equal
  • assert_matches_regex
  • assert_err_matches_regex
  • assert_matches_snapshot
  • assert_matches_inline_snapshot
  • assert_ok
  • assert_err

See https://docs.rs/k9 for API documentation

snapshot!() macro

Snapshot macro provides the functionality to capture the Debug representation of any value and make sure it does not change over time.

If it does change, the test will fail and print the difference between "old" and "new" values.

If the change is expected and valid, running cargo test with K9_UPDATE_SNAPSHOTS=1 env variable set will automatically take the new value and insert it into the test source code file as a second argument, after which all subsequent test runs should start passing again.

inline_snapshot_demo

assert_equal!() macro

Rust already provides a good built-in test runner and a set of assertion macros like assert! and assert_eq!. They work great for for quick unit tests, but once the codebase and test suites grows to a certain point it gets harder and harder to test things and keep tests readable.

For example, when testing that two structs are equal using assert_eq! macro the output does not provide a lot of help in understanding why exactly this test failed.

#[derive(PartialEq, Debug)]
struct Person {
    name: &'static str,
    age: usize,
}

#[test]
fn test_eq() {
    let person1 = Person {name: "Bob", age: 12 };
    let person2 = Person {name: "Alice", age: 20 };
    assert_eq!(person1, person2, "These two must be the same person!");
}

All we get is usually a wall of wite text collapsed into a single line and you have to find the difference between two structs yourself. Which becomes very time consuming when structs are 10+ fields.

---- eq::test_eq stdout ----
thread 'eq::test_eq' panicked at 'assertion failed: `(left == right)`
  left: `Person { name: "Bob", age: 12 }`,
 right: `Person { name: "Alice", age: 20 }`: These two must be the same person!', src/eq.rs:13:5

using k9::assert_equal macro improves this output and prints the difference between two structs:

use k9::assert_equal;
assert_equal!(person1, person2, "These two must be the same person!");

assert_equal_example

Non-equality based assertions

Testing equality is very simple and can definitely work for most of the cases, but one of the disadvantages of only using assert! and assert_eq! is the error messages when something fails. For example, if you're testing that your code produces valid URL

let url = generate_some_url();
assert_eq!(URL_REGEX.is_match(url), true);

What you get is

thread 'eq::test_eq3' panicked at 'assertion failed: `(left == right)`
  left: `false`,
 right: `true`', src/eq.rs:19:5

Which doesn't help much. Especially, if you're new to the code base, seeing things like expected 'true' but got 'false' will make you go and look at the code before you even know what the problem can be, which can be very time consuming.

What we probably want to see is:

assert_matches_regex_example

Which gives us enough context on what the problem is and how to fix it without for us having to go and run/debug the test first.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].