EveryRole

How to write test cases that catch real bugs

A test case is one input and one expected result at one stop. How to write test cases for a real form, and the three most teams leave out.

To write test cases that catch bugs, give each one three things: where you are, what you do, and what must come out. If one of the three is missing, you have a note, and a note can’t fail.

Most test cases we see are missing the third. “Check that creating an item works” says where and what: it is a test scenario, not yet a test case. It never says what “works” looks like, so whoever runs it decides on the spot, and they decide yes.

Here is how we write them, on a form small enough to hold in your head.

Start with the journey, then the stops

Our practice app has items. An editor logs in, opens “New item”, types a name and a note, presses “Create”, and lands on the item’s page. That whole trip is a journey: one kind of user getting one thing done.

A journey is made of stops. A stop is a place where the person does something the app has to answer: the login form, the new item form, the list. Pages they only pass through are not stops.

A journey of three stops with the four cases of the form stop listed under it: good input, empty, too long, and wrong then right
One journey, three stops. The cases belong to a stop, never to the journey as a whole.

Cases hang off stops. If you write cases against the whole journey (“create an item with an empty name, then check the list”), every case repeats the login and the navigation, and when the login breaks all of them fail at once and tell you nothing about the form.

How to write a test case: one input, one result

At the “New item” stop there are two fields. The name is required and takes at most 60 characters. The note is optional.

A case for that stop is one row:

CaseWhat is typedWhat must come out
Good inputName Sample item, note A short sample noteThe item’s page opens. Its heading is Sample item, the note is under it.
EmptyNothingThe form stays. The name field says “Please fill out this field.” (the browser’s own message). No item is created.
Too longA name of 61 charactersThe field takes only the first 60. Sent past the browser, 61 characters are refused with a message.
Wrong, then rightNothing, then Sample itemThe error goes away. Exactly one item is created.

Read the right-hand column again. Each cell is something you can look at and say yes or no to. “No item is created” is checkable: open the list, count. “The form handles it gracefully” is not.

A rule we hold ourselves to: if two people could run the case and disagree about whether it passed, the expected result isn’t finished.

The cases people skip

Everyone writes the first row. It is the one you did by hand while building the feature. The bugs live in the other three, because nobody tried them.

Empty. Press the button with nothing typed. It costs ten seconds and it finds real things: a server error page instead of a message, a blank item saved, a spinner that never stops. We wrote a whole post on the empty form.

The limit. If a field has a limit, try the limit and one past it. Limits are checked in two places (the browser and the server) and nothing makes the two agree. More in boundary values.

Wrong, then right. After an error, fix the input and send again. Forms keep state, and the state after an error is the least tested state in most apps: the button that stays disabled, the error that stays on screen above a now-valid field, the item that gets created twice.

You don’t need forty cases per form. For a form like this one, four to six cover most of what breaks. More than that and nobody reads the results.

Write down who

The same stop gives a different right answer to a different kind of user. In our practice app a viewer can open the list but their “New item” button is disabled. So “Good input” has no meaning for a viewer. Their case at this stop: the button is disabled, and opening /items/new by its address is refused.

Put the kind of user on the case. A test case with no “who” was written from the builder’s own account, which is usually an admin, which is the account least like your users.

Say what the expected result is based on

This is the part that goes wrong quietly. Somebody has to decide that “the item’s page opens with its name on it” is the right answer. Usually that decision is made once, by the person who wrote the feature, in their head, and never written down. Six months later the page shows the name twice and nobody can say whether that is a bug. A case with no written answer is how hollow passes happen.

So write the expected result from a real run you looked at. Run the case once, look at what the app did, and if it is right, that picture is the expected result.

That is how EveryRole does it. For each case it shows the first result with what was typed beside what the page answered, and asks one question.

EveryRole asking "Is this first result right?" for the empty case. Under Typed it says Nothing typed, beside what the page said about the fields: Name: Please fill out this field. Below are the answers No, it's wrong, Not sure yet and Yes, it's right.
The empty case of the new item form: what was typed beside what the page answered, and the three answers. A yes makes this the answer every later run is compared with.

A yes keeps that answer. From then on each run compares with it, in code. A no marks the case as a wrong result until the app gives one you approve. If the answer changes later, you get asked. It never passes silently.

You can do the same by hand: a screenshot and one sentence per case, in the same document as the table. It is slower, and it works.

A short checklist

Before you call a test case written:

  • It names one kind of user.
  • It belongs to one stop, and says how to get there.
  • It says exactly what is typed or pressed. “A valid name” is not exact. Sample item is.
  • Its expected result is something on the page that two people would agree on.
  • It says what must not happen, when that matters (no item created, no email sent).

Then write the three cases next to it that you were going to skip.

If you want the list of cases to try on any form, we keep one in a test case checklist for any form. If you’d rather see the cases written for your own app, EveryRole explores it and suggests the journeys, stops and cases itself. You keep the ones that matter.

Keep reading

Test cases

A test without an expected result isn’t a test

The expected result is the half of a test case people leave vague. How to write one that can fail, what to leave out of it, and who gets to say what is right.

5 min read

Test cases

Boundary value testing, without the theory

Boundary value analysis on a real form: a field of 1 to 60 characters needs four test values, all at the edges. What to type, and what we found in our own app.

6 min read