Skip to content

kylef-archive/jsonschema-test

Repository files navigation

JSON Schema Testing

Build Status

jsonschema-test is a tool for writing and running tests against a given JSON Schema. You can write a set of test-cases including example JSON values and if they should validate or not against the given JSON Schema.

Installation

pip install jsonschema-test

Usage

To use jsonschema-test, you will need to write a collection of tests. The tests are decoupled from any language and are written in JSON.

Example

Test Suite

A test suite is a collection of test's and test cases. See the test suite structure for more information

[
    {
        "description": "a person",
        "tests": [
            {
                "description": "validates with a name",
                "data": {
                    "name": "Kyle"
                },
                "valid": true
            },
            {
                "description": "fails validation without a name",
                "data": {
                },
                "valid": false
            }
        ]
    }
]

Schema

A JSON Schema to test.

{
    "type": "object",
    "properties": {
        "name": {
            "type": "string"
        }
    },
    "required": [ "name" ]
}

Running the tests

jsonschema-test example/schema.json example/tests.json

Test Suite Structure

There is a JSON Schema file for the test suite structure.

Suite

A test suite is a logical group of Test's. It's a simple JSON file with an array containing each test.

Test

Properties

  • description (string, required) - A short description of what this test tests.
  • tests (array[Case], required) - A collection of test cases.
  • skip (boolean, optional) - Whether to skip the test. This defaults to false.

Case

Properties

  • description (string, required) - The description of this test case.
  • data (any, required) - The JSON used against the JSON Schema.
  • valid (boolean, required) - If the data should validate or not.
  • skip (boolean, optional) - Whether to skip the case. This defaults to false.

Credits

This tool was built by Kyle Fuller (@kylefuller).

License

jsonschema-test is released under the BSD license. See LICENSE.

About

A tool for writing and running tests against a given JSON Schema

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages