Crates.io | restest |
lib.rs | restest |
version | 0.1.0 |
source | src |
created_at | 2021-12-09 10:14:01.47311 |
updated_at | 2021-12-09 10:14:01.47311 |
description | Black-box integration test for REST APIs in Rust. |
homepage | |
repository | |
max_upload_size | |
id | 495097 |
size | 67,789 |
Black-box integration test for REST APIs in Rust.
This crate provides the [assert_api
] macro that allows to declaratively
test, given a certain request, that the response emitted by the server is
correct.
#![feature(assert_matches)]
use serde::{Deserialize, Serialize};
restest::port! { 8080 }
restest::assert_api! {
POST "/user",
PostUser {
year_of_birth: 2000,
} => User {
year_of_birth: 2000,
..
}
}
#[derive(Debug, Serialize)]
struct PostUser {
year_of_birth: usize,
}
#[derive(Debug, Deserialize)]
struct User {
year_of_birth: usize,
id: Uuid
}
The [port
] macro sets the port at which the request must be run.
The tests are written as normal Rust tests (ie: functions annotated with
#[test]
). As we're using asynchronous code, we must write async tests,
perhaps using #[tokio::test]
.
More specifically, the [assert_api
] macro can be used in order to query
the server API and analyze its response.
The server must be running in the background when cargo test
is run.
The nightly
feature allows the [assert_api
] macro to expand to
nightly-specific code. This offers the following features:
assert_matches
),let_else
) (still WIP).These two features must be added at the crate root using the following two lines:
#![feature(assert_matches)]
#![feature(let_else)]
We have a Code of Conduct so as to create a more enjoyable community and work environment. Please see the CODE_OF_CONDUCT file for more details.
Licensed under either of
at your option.
Dual MIT/Apache2 is strictly more permissive