Writing tests

You can exercise handlers directly without binding to a real port. Crow lets you call handle() on a synthetic request and inspect the response.

Unit tests

#include "crow.h"
#include "doctest.h"

TEST_CASE("hello returns greeting") {
    crow::SimpleApp app;
    CROW_ROUTE(app, "/")([] { return "hi"; });

    crow::request req;
    req.url = "/";
    crow::response res;
    app.handle(req, res);

    CHECK(res.code == 200);
    CHECK(res.body == "hi");
}

Integration tests

For end-to-end coverage, start the app with run_async() and hit it with libcurl or any HTTP client:

auto handle = app.port(0).run_async();   // port 0 = auto-pick
auto port   = app.port();                  // discover the bound port
// ... issue requests against http://localhost:port ...
app.stop();