O'Reilly logo

Continuous Integration, Delivery, and Deployment by Sander Rossel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing tests

Now, let's write a couple of tests for our API. As I mentioned in the introduction, we can write tests using JavaScript. Get your GET localhost/todo?id=1 from your history and select the Tests tab (in the request, not the response). You will see a couple of snippets on the right-hand side that you can click after which they will be added to your script. For example, we can use the Response body: Contains string snippet and change it a little so we can verify that somewhere in our response we get id 1:

tests["Body contains id 1"] = responseBody.has('"id":1,');

We need to test for the raw response (which has no spaces or new lines) rather than the pretty, printed response (which has spaces and new lines). When you send the request ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required