All Projects → theramis → Snapper

theramis / Snapper

Licence: mit
Bringing Jest-esque Snapshot testing to C#

Projects that are alternatives of or similar to Snapper

generator-react-jest-tests
A React Jest test generator. Generates snapshot tests for React components.
Stars: ✭ 34 (-60%)
Mutual labels:  test, snapshot-testing, testing-tools
Testfx
MSTest V2 framework and adapter
Stars: ✭ 391 (+360%)
Mutual labels:  test, testing-tools
Testcafe
A Node.js tool to automate end-to-end web testing.
Stars: ✭ 9,176 (+10695.29%)
Mutual labels:  test, testing-tools
Carina
Carina automation framework: Web, Mobile, API, DB
Stars: ✭ 549 (+545.88%)
Mutual labels:  test, testing-tools
puppeteer-screenshot-tester
Small library that allows us to compare screenshots generated by puppeteer in our tests.
Stars: ✭ 50 (-41.18%)
Mutual labels:  test, testing-tools
Kotest
Powerful, elegant and flexible test framework for Kotlin with additional assertions, property testing and data driven testing
Stars: ✭ 3,234 (+3704.71%)
Mutual labels:  test, testing-tools
Mocha
☕️ simple, flexible, fun javascript test framework for node.js & the browser
Stars: ✭ 20,986 (+24589.41%)
Mutual labels:  test, testing-tools
carina-demo
Carina demo project.
Stars: ✭ 40 (-52.94%)
Mutual labels:  test, testing-tools
Httptest
Qiniu httptest utilities
Stars: ✭ 571 (+571.76%)
Mutual labels:  test, testing-tools
Haskell Hedgehog
Release with confidence, state-of-the-art property testing for Haskell.
Stars: ✭ 584 (+587.06%)
Mutual labels:  test, testing-tools
Faker
Faker is a pure Elixir library for generating fake data.
Stars: ✭ 673 (+691.76%)
Mutual labels:  test, testing-tools
reducer-tester
Utilities for testing redux reducers
Stars: ✭ 19 (-77.65%)
Mutual labels:  test, snapshot-testing
gmock-xcode
Xcode integration for GoogleMock through XCTest
Stars: ✭ 18 (-78.82%)
Mutual labels:  test, testing-tools
Zora
Lightest, yet Fastest Javascript test runner for nodejs and browsers
Stars: ✭ 356 (+318.82%)
Mutual labels:  test, testing-tools
kotest-gradle-plugin
A gradle plugin for Kotest
Stars: ✭ 18 (-78.82%)
Mutual labels:  test, testing-tools
Tparse
CLI tool for analyzing and summarizing go test output. Pipe friendly. CI/CD friendly.
Stars: ✭ 445 (+423.53%)
Mutual labels:  test, testing-tools
Mts
Project of Multi-protocol Test Tool opensourced by Ericsson
Stars: ✭ 34 (-60%)
Mutual labels:  test, testing-tools
qiniutest
Qiniu httptest tool: qiniutest
Stars: ✭ 36 (-57.65%)
Mutual labels:  test, testing-tools
Wasmite
Now WebAssembly has proper testing, unit-testing and debugging 🤗
Stars: ✭ 20 (-76.47%)
Mutual labels:  test, testing-tools
Vue Testing Library
🦎 Simple and complete Vue.js testing utilities that encourage good testing practices.
Stars: ✭ 567 (+567.06%)
Mutual labels:  test, testing-tools

Snapper V2

Bringing Jest-esque Snapshot testing to C#

Build Status Nuget (with prereleases) license

Snapper is a NuGet library which makes snapshot testing very easy in C#. Snapshot testing can simplify testing and is super useful when paired with Golden Master testing or contract testing APIs. It is very heavily based on Jest Snapshot Testing framework.

See https://theramis.github.io/Snapper/ for the full documentation.

What is Snapper?

The best way to describe what Snapper does by going through an example. Imagine you have the following test where are retrieving a user from a service.

[Fact]
public void MyTest()
{
  var myUser = _userService.GetUser(id);
  Assert.Equal("MyUser", myUser.Username);
  Assert.Equal("[email protected]", myUser.Email);
  Assert.Equal("myhash", myUser.PasswordHash);
  ...
  ...
}

As you can imagine the assertion steps in the test can get very long and hard to read. Now lets see what the test would look like if Snapper is used.

[Fact]
public void MyTest()
{
  var myUser = _userService.GetUser(id);
  myUser.ShouldMatchSnapshot();
}

The test above is now asserting the myUser object with a snapshot stored on disk. Snapper helps you create this snapshot at the beginnging (see Quick Start).

This is the basis of snapshot testing. The idea being a baseline is first generated (in this case a json file which is our snapshot) and then everytime the test runs the output is compared to the snapshot. If the snapshot and the output from the tests don't match the test fails!

As you can see using Snapper the test is now much smaller and easier to read but that's not all. Using Snapper brings with it a lot more benefits!

Why use Snapper?

Benefits of using Snapper/snapshot testing vs traditional assertions

  • Much easier to read - It's quite common to have a large list of assertions which can be hard to read. Snapper makes your tests a lot shorter and easier to read!
  • Very difficult to miss properties to assert - It's hard to validate that all properties have are being asserted using traditional assertions. By using Snapper the whole object asserted which means all properties are always asserted, so there is no chance of missing properties!
  • Captures changes to the object being asserted - It's quite common to add new properties to our objects over time. e.g. Adding FirstName to the myUser object above. Using traditional assertions the test would still pass and it's easy to forget to update the test. Using Snapper the test would immediately fail since it's a change in the system and the developer should verify if the change was expected!
  • Much quicker to write tests - Writing all those assertions above can be time consuming. With Snapper a json file is generated with the object which the developer can quickly verify!

When to use Snapper?

Use cases where Snapper/snapshot testing really shines

  • Contract testing - Testing your contract has not changed is a major part of maintaining any library/API. Snapper is excellent for this! Using Snapper any changes to the contract would immediately fail a test which lets the developer know that they might be breaking a contract they didn't expect.
  • Asserting complex objects - Sometimes you have to assert complex objects which can be hard and time consuming to get right. Snapper makes this easy and quick.
  • Golden Master testing - Golden master testing is a technique where you capture the behaviour of a system. Snapper is perfect for this as you can easily assert the behaviour without the complex setup and assertions. Snapper would also fail as soon as the behaviour of the system changes

The use cases above are just some of the examples I've found where Snapper is super useful. Feel free to try them in other situation you think would be useful.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Florian Gather

💻 🤔

Tomas Bruckner

💻

Michael Kriese

💻 🤔 🐛

Taylor Kimmett

💻

Patrick Lehner

🐛

Piotr Litwinski

🐛

Warren Ferrell

💻

Aaron Roberts

💻 🤔

This project follows the all-contributors specification. Contributions of any kind welcome!

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].