Crates.io docs.rs pipeline status coverage report license dependency status lines of code

rtest - Resource based test framework

There are many unit-test frameworks in rust. This framework focuses on integration-testing, that means external software, not necessarily written in rust.

rtest works by using stateful resources. It uses macros to build a executable binary that can handle all your filters and returns a nice output.

Imagine you are hosting a webshop and want to verify it works with integration-tests. ```rust struct Orderinfo{item: String} struct Order{id: String}

const SHOP: &str = "http://shop.example.com";

[rtest]

async fn place_order(info: Orderinfo) -> Result { let client = reqwest::Client::new(); let id = client.post(format!("{}/v1/order/{}", SHOP, info.item)).send().await?.text().await?; Ok(Order{id}) }

[rtest]

async fn checkorder(order: Order) -> Result { let res = reqwest::get(format!("{}/v1/order/{}", SHOP, order.id)).await?; assertne!(res.status(), 404); Ok(order) }

[rtest]

async fn cancelorder(order: Order) -> Result<(), std::error::Error> { let client = reqwest::Client::new(); let id = client.delete(format!("{}/v1/order/{}", SHOP, order.id)).send().await?; assertne!(res.status(), 200); Ok(()) }

[tokio::main]

async fn main() { let water = Orderinfo{ item: "water".tostring() }; let pizza = Orderinfo{ item: "pizza".tostring() }; let context = rtest::Context::default().withresource(water).withresource(pizza); rtest::run!(context) } ```

The test framework will know that in order to test the check_order function it first needs to have a Order. But the only way to generate such a order is through the place_order test. cancel_order will consume the order and no longer make it useable.

Yes, you can trick it by removing all tests that generate an Order - the framework will notice that on runtime and fail. It might be possible that multiple routes are valid to test all functions, in case of an error the route it took will be dumped. Let's assume checking an order with water will fail. The framework might decide to create another Order with pizza because it cannot verify deletion otherwise, tests might be executed multiple times.

```md

rtest result - 2023-08-11:10:23:45 - FAILURE

[✓] 4/4 dos.rs [✓] 6/6 reviews.rs [x] 1/5 sqlinjection.rs [x] 1/3 main.rs

Failures

sqlinjection::searchbobbytables

main::cancel_order

Path: placeorder(order) -> checkorder(order) -> cancel_order(order)

```

Features: - [X] Allow any Input/Output Resources (up to 5) - [X] Custom Errors - [X] Custom Context (though rarely needed) - [ ] Reorder execution and no longer depend on random execution model - [ ] Multithread support - [X] Async Support - [ ] Automatically create new Resources on demand - [ ] implement #[setup] macro to create optional function to generate Ressource if necessary - [X] Capture Panics (needed for asserts) - [ ] Capture println - [X] Capture logs