jsonschema-rs/jsonschema-test-suite
Dmitry Dygalo 9aae87e573 build: Update builds
Signed-off-by: Dmitry Dygalo <dmitry@dygalo.dev>
2024-04-14 18:24:03 +02:00
..
proc_macro chore: Clarify error on missing test suite 2024-03-03 21:26:10 +01:00
src chore: Port `json-schema-test-suite` as a local dependency 2021-07-23 10:17:53 +02:00
test_case chore: Update to Rust 2021 edition in all crates 2022-04-10 23:31:34 +02:00
tests chore: Port `json-schema-test-suite` as a local dependency 2021-07-23 10:17:53 +02:00
CHANGELOG.md chore: Port `json-schema-test-suite` as a local dependency 2021-07-23 10:17:53 +02:00
Cargo.toml chore: Update to Rust 2021 edition in all crates 2022-04-10 23:31:34 +02:00
LICENSE chore: Port `json-schema-test-suite` as a local dependency 2021-07-23 10:17:53 +02:00
README.md docs: Fix typo in jsonschema-test-suite README 2021-10-02 20:46:46 +02:00
rustfmt.toml build: Update builds 2024-04-14 18:24:03 +02:00

README.md

json_schema_test_suite

ci codecov Crates.io docs.rs

The crate provides a procedural macro attribute that allow to generate all the test cases described by JSON-Schema-Test-Suite.

The main objective is to ensure that for each test a mock server is started and will be able to capture all the requests, ensuring that tests can be ran only interacting with cargo test

In order to use the procedural macro attribute there are few assumptions that are made:

  • lazy_static dependency is added into your [dev-dependencies] section of the Cargo.toml file
  • mockito dependency is added into your [dev-dependencies] section of the Cargo.toml file
  • serde-json dependency is added into your [dev-dependencies] section of the Cargo.toml file
  • the annotated method signature should be: fn (&str, json_schema_test_suite::TestCase) -> ()

How to use

Cargo.toml

# Ensure that the following lines are present into your Cargo.toml file
[dev-dependencies]
json_schema_test_suite = "0"
# Be careful with dependencies version (using `*` version is never recommended).
# The proc-macro uses nothing fancy with the dependencies, so any version should work well :)
lazy_static = "*"
mockito = "*"
serde_json = "*"

Rust test file example

use json_schema_test_suite::{json_schema_test_suite, TestCase};

// If no tests should be ignored
#[json_schema_test_suite(
    // path separator is assumed to be `/` (regardless of the run platform)
    "path/to/JSON-Schema-Test-Suite/repository",
    // test directory (in <JSON-Schema-Test-Suite>/tests/<test_directory>)
    "draft7"
)]
// If some tests needs to be ignored, just defined them into `{ ... }` as follow
#[json_schema_test_suite(
    // path separator is assumed to be `/` (regardless of the run platform)
    "path/to/JSON-Schema-Test-Suite/repository",
    // test directory (in <JSON-Schema-Test-Suite>/tests/<test_directory>)
    "draft6",
    {   // Names, as generated by the macro, of the tests to ignore
        // NOTE: They can be regular expression as well.
        "name of the tests to ignore",
    }
)]
fn my_simple_test(
    // address of the HTTP server providing the remote files of JSON-Schema-Test-Suite.
    // The format will be: `hostname:port`.
    // This parameter is passed because by starting a mock server we might not start it
    // into `localhost:1234` as expected by JSON-Schema-Test-Suite
    server_address: &str,
    // Representation of the test case
    test_case: TestCase,
) {
    // TODO: Add here your testing logic
}

License: MIT