All Projects → jfilipczyk → gomatch

jfilipczyk / gomatch

Licence: MIT License
Library created for testing JSON against patterns.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to gomatch

Nspec
A battle hardened testing framework for C# that's heavily inspired by Mocha and RSpec.
Stars: ✭ 242 (+490.24%)
Mutual labels:  tdd, bdd
bdd-for-all
Flexible and easy to use library to enable your behavorial driven development (BDD) teams to easily collaborate while promoting automation, transparency and reporting.
Stars: ✭ 42 (+2.44%)
Mutual labels:  tdd, bdd
chai
BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.
Stars: ✭ 7,842 (+19026.83%)
Mutual labels:  tdd, bdd
bdd-for-c
A simple BDD library for the C language
Stars: ✭ 90 (+119.51%)
Mutual labels:  tdd, bdd
respect
RSpec inspired test framework for Reason/OCaml/Bucklescript.
Stars: ✭ 28 (-31.71%)
Mutual labels:  tdd, bdd
Bandit
Human-friendly unit testing for C++11
Stars: ✭ 240 (+485.37%)
Mutual labels:  tdd, bdd
tddd-starter
Laravel TDDD Starter App
Stars: ✭ 23 (-43.9%)
Mutual labels:  tdd, bdd
Lightbdd
BDD framework allowing to create easy to read and maintain tests.
Stars: ✭ 195 (+375.61%)
Mutual labels:  tdd, bdd
java-8-matchers
Hamcrest Matchers for Java 8 features
Stars: ✭ 23 (-43.9%)
Mutual labels:  tdd, matcher
mocha-cakes-2
A BDD plugin for Mocha testing framework
Stars: ✭ 44 (+7.32%)
Mutual labels:  tdd, bdd
Pester
Pester is the ubiquitous test and mock framework for PowerShell.
Stars: ✭ 2,620 (+6290.24%)
Mutual labels:  tdd, bdd
showroom
Universal development and automated test environment for web components
Stars: ✭ 89 (+117.07%)
Mutual labels:  tdd, bdd
Add
Разработка с управляемым качеством на 1С
Stars: ✭ 210 (+412.2%)
Mutual labels:  tdd, bdd
TestBox
TestBox is a next generation testing framework for ColdFusion (CFML) that is based on BDD (Behavior Driven Development) for providing a clean obvious syntax for writing tests. It also includes MockBox, our mocking and stubbing framework.
Stars: ✭ 54 (+31.71%)
Mutual labels:  tdd, bdd
Cucumber Rust
Cucumber testing framework for Rust. Fully native, no external test runners or dependencies.
Stars: ✭ 210 (+412.2%)
Mutual labels:  tdd, bdd
chai-exclude
Exclude keys to compare from a deep equal operation with chai expect or assert.
Stars: ✭ 33 (-19.51%)
Mutual labels:  tdd, bdd
Spek
A specification framework for Kotlin
Stars: ✭ 2,143 (+5126.83%)
Mutual labels:  tdd, bdd
Catch2
A modern, C++-native, test framework for unit-tests, TDD and BDD - using C++14, C++17 and later (C++11 support is in v2.x branch, and C++03 on the Catch1.x branch)
Stars: ✭ 14,330 (+34851.22%)
Mutual labels:  tdd, bdd
ginkgo4j
A Java BDD Testing Framework (based on RSpec and Ginkgo)
Stars: ✭ 25 (-39.02%)
Mutual labels:  tdd, bdd
apple-mango
Python BDD Pattern
Stars: ✭ 18 (-56.1%)
Mutual labels:  tdd, bdd

Gomatch

Build Status codecov GoDoc Go Report Card

Library created for testing JSON against patterns. The goal was to be able to validate JSON focusing only on parts essential in given test case so tests are more expressive and less fragile. It can be used with both unit tests and functional tests.

When used with Gherkin driven BDD tests it makes scenarios more compact and readable. See Gherkin example

Contests

Installation

go get github.com/jfilipczyk/gomatch

Basic usage

actual := `
{
  "id": 351,
  "name": "John Smith",
  "address": {
    "city": "Boston"
  }
}
`
expected := `
{
  "id": "@number@",
  "name": "John Smith",
  "address": {
    "city": "@string@"
  }
}
`

m := gomatch.NewDefaultJSONMatcher()
ok, err := m.Match(expected, actual)
if ok {
  fmt.Printf("actual JSON matches expected JSON")
} else {
  fmt.Printf("actual JSON does not match expected JSON: %s", err.Error())
}

Available patterns

  • @string@
  • @number@
  • @bool@
  • @array@
  • @uuid@
  • @email@
  • @wildcard@
  • @...@ - unbounded array or object

Unbounded pattern

It can be used at the end of an array to allow any extra array elements:

[
  "John Smith",
  "Joe Doe",
  "@...@"
]

It can be used at the end of an object to allow any extra keys:

{
  "id": 351,
  "name": "John Smith",
  "@...@": ""
}

Gherkin example

Gomatch was created to use it together with tools like GODOG. The goal was to be able to validate JSON response focusing only on parts essential in given scenario.

Feature: User management API
  In order to provide GUI for user management 
  As a frontent developer
  I need to be able to create, retrive, update and delete users

  Scenario: Get list of users sorted by username ascending
    Given the database contains users:
    | Username   | Email                  |
    | john.smith | john.smith@example.com |
    | alvin34    | alvin34@example.com    |
    | mike1990   | mike.jones@example.com |
    When I send "GET" request to "/v1/users?sortBy=username&sortDir=asc"
    Then the response code should be 200
    And the response body should match json:
    """
    {
      "items": [
        {
          "username": "alvin34",
          "@...@": ""
        },
        {
          "username": "john.smith",
          "@...@": ""
        },
        {
          "username": "mike1990",
          "@...@": ""
        }
      ],
      "@...@": ""
    }
    """

License

This library is distributed under the MIT license. Please see the LICENSE file.

Credits

This library was inspired by PHP Matcher

Logo

The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/). Gomatch logo was based on a gopher created by Takuya Ueda (https://twitter.com/tenntenn). Licensed under the Creative Commons 3.0 Attributions license. Gopher eyes were changed.

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