2个不稳定版本
0.3.0 | 2020年6月29日 |
---|---|
0.2.0 | 2020年6月22日 |
0.1.0 |
|
#666 in 过程宏
58 每月下载量
在 jsonschema 中使用
120KB
142 行
json_schema_test_suite
该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