4 ms·
So, myself and many folks I know have taken to writing tests in the form of ".http" files that can be executed by IDE extensions in VS Code/IDEA. Those basical
by gavinray 1y ago
So, myself and many folks I know have taken to writing tests in the form of ".http" files that can be executed by IDE extensions in VS Code/IDEA.
Those basically go in the form
POST http://localhost:8080/api/foo
Content-Type: application/json
{ "some": "body" }
And then we have a 1-to-1 mapping of "expected.json" outputs for integration tests.
We use a bespoke bash script to run these .http file with cURL, and then compare the outputs with jq, log success/failure to console, and write "actual.json"
Can I use HURL in a similar way? Essentially an IDE-runnable example HTTP request that references a JSON file as the expected output?
And then run HURL over a directory of these files?
- xnorswap 1y agoI like this approach. Is your expected.json the actual response body, or is it an object containing body, status, header values, and time-taken, etc?
- gavinray 1y agoIt's only the response body, but that's due to not having a usecase to validate headers or status code. I really like it because it serves 3 purposes: - API docs/examples that you can interact with - Test cases - Manually invoking API endpoints when working on the underlying code, in an iterative loop
- digikata 1y agoYou can use hurl in this way. I have projects with a test directory of hurl files, one hurl file per test case. The cases can run one or more http requests. The hurl file can reference external files, capture values from responses for subsequent requests, validate status and outputs. Hurl has various test runner modes and will optionally output overall test results in various parsable formats if you have a larger reporting framework that you would like to hook into.
- gavinray 1y agoThat's great to know! Do you have an example on-hand by chance? If that's possible, I guess the only thing I'd request is interopability with the REST Client ".http" files that VS Code/JetBrains IDE's support then. UPDATE: Found it, looks like you can do it via the below POST https://example.org/api/tests Content-Type: application/json file,insert_user.request.json; [Asserts] body == file,insert_user.expected.json; So that just leaves the IDE integration bit.