#json-schema #attributes #test-cases #proc-macro #procedural #run

json_schema_test_suite

用于运行JSON-Schema-Test-Suite中描述的所有测试案例的过程宏属性

2个不稳定版本

0.3.0 2020年6月29日
0.2.0 2020年6月22日
0.1.0 2020年6月22日

#666 in 过程宏

Download history 10/week @ 2024-03-11 14/week @ 2024-03-18 9/week @ 2024-03-25 96/week @ 2024-04-01 9/week @ 2024-04-08 17/week @ 2024-04-15 20/week @ 2024-04-22 6/week @ 2024-04-29 9/week @ 2024-05-06 37/week @ 2024-05-13 14/week @ 2024-05-20 10/week @ 2024-05-27 17/week @ 2024-06-03 10/week @ 2024-06-10 16/week @ 2024-06-17 14/week @ 2024-06-24

58 每月下载量
jsonschema 中使用

MIT 许可证

120KB
142

json_schema_test_suite

ci codecov Crates.io docs.rs

该crate提供了一个过程宏属性,允许生成由JSON-Schema-Test-Suite描述的所有测试案例。

主要目标是确保对于每个测试,都会启动一个模拟服务器,并能够捕获所有请求,确保测试只能通过与cargo test进行交互来运行。

为了使用过程宏属性,这里有一些假设

  • lazy_static 依赖项添加到你的 [dev-dependencies] 部分的 Cargo.toml 文件
  • mockito 依赖项添加到你的 [dev-dependencies] 部分的 Cargo.toml 文件
  • serde-json 依赖项添加到你的 [dev-dependencies] 部分的 Cargo.toml 文件
  • 注释的方法签名应该是:fn &str, json_schema_test_suite::TestCase) -> ()

如何使用

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 测试文件示例

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
}

许可证:MIT

依赖项

~2.7–4.5MB
~84K SLoC