Talking About TestingATT</>
API Testing with Bruno

Score 100% on the quiz to continue

Lesson
Free Preview

Your first request

Send a GET request, read the response, and check it with declarative assertions.

Let's start with the most important check of any API, the happy path: sending a GET request to the /emojis endpoint and confirming it responds successfully, with a status code of 200 and a body that has the expected structure.

Exploring by hand, you would send the request, glance at the response, and move on. The difference in this course is that you write down what you expect as assertions, so Bruno can check it for you every time the request runs, including in CI, when nobody is looking.

Commands overview 📖

Creating a request

Right-click the collection in the sidebar (or use its three-dot menu) and choose New Request. Give it a name, choose the method, and type the URL.

Syntax:

Name:   <a name that describes what the request checks>
Method: GET
URL:    http://localhost:3001/emojis
👨‍🏫 The name becomes the file name on disk, and it is the label you will read in every run report. Name requests after what they check, not after the endpoint alone.

Sending a request and reading the response pane

Click the arrow button at the end of the URL bar (or press Cmd+Enter / Ctrl+Enter). The response pane on the right shows:

  • The status code and text (for example, 200 OK)
  • The time the request took, and the response size
  • The response body, formatted as JSON
  • The response headers, in their own tab
👨‍🏫 The Timeline tab shows the exact request Bruno sent, with the final URL and headers. When a response surprises you, check what was actually sent before blaming the API.

The Assert tab (declarative assertions)

The Assert tab lets you write checks without writing code. Each row has three parts: an expression (what to check), an operator (how to compare), and a value (what you expect, when the operator needs one).

Syntax:

<expression>   <operator>   <value>

Example:

res.status              eq         200
res.body.emojis         isArray
res.body.pageInfo       isDefined

Some operators you will use often:

  • eq and neq: equal and not equal
  • isArray, isNumber, isString, isDefined: type and presence checks
  • gt, gte, lt, lte: number comparisons
  • length: the length of an array or a string

After you send the request, the Tests tab of the response pane lists every assertion as passed or failed.

What an assertion looks like on disk

Bruno saves the request, including its assertions, as a YAML file inside the collection folder:

Example:

info:
  name: get-emojis
  type: http
  seq: 1

http:
  method: GET
  url: http://localhost:3001/emojis

runtime:
  assertions:
    - expression: res.status
      operator: eq
      value: "200"
    - expression: res.body.emojis
      operator: isArray
👨‍🏫 You never have to edit this file by hand, but reading it once explains why Bruno collections work so well in git: a new assertion is a two-line diff anyone can review.

Suggested content 📚 and documentation links 🔗

Exercise 🎯

In your emoji-api-tests collection, create a request named get-emojis that sends a GET to http://localhost:3001/emojis. Send it and read the response pane.

Then, in the Assert tab, add assertions checking that:

  • res.status equals 200
  • res.body.emojis is an array
  • res.body.pageInfo is defined
  • res.body.pageInfo.currentPage equals 1

Send the request again and confirm every assertion passes. You can see each assertion's pass or fail result in the Tests tab of the response pane. Then change the expected status to 201, send it, and watch that assertion fail. Change it back to 200 before moving on.

👨‍🏫 Watching an assertion fail on purpose is not a waste of time. An assertion you have never seen fail might not be checking anything at all.

Save the request (Cmd+S / Ctrl+S), then run git status in your terminal to see the new file. Commit it and push.

Show the world what you learned 🌎

To show your professional network what you learned in this lesson, post the following on LinkedIn.

I am taking the "API Testing with Bruno" course by @Walmyr Lima e Silva Filho at the @Talking About Testing School, and I just created my first Bruno request with declarative assertions on the status code and the response body, saved as a plain file in my git repository. #TalkingAboutTesting #TATSchool #APITestingWithBruno #Bruno #APITesting

👨‍🏫 Remember to tag me in your post. Here is my LinkedIn profile.

Quiz

Question 1 of 2
Score: 0

Why is it worth changing an assertion so it fails on purpose, and then changing it back?

Score 100% on the quiz to continue