Source: https://everyrole.dev/blog/search-functionality-test-cases

# Test cases for search functionality: the four that matter

Test cases for search functionality, cut down to four: a term with results, a term with none, cleared, and with a filter. What to type, what must come out.

Nov 22, 2026  5 min read  by the EveryRole team

The test cases for search functionality that find bugs are four: a term that has results, a term that has none, the search cleared again, and the search used together with a filter. The long lists of a hundred search cases contain these four somewhere in the middle, between “search with 10,000 characters” and “search in upper case”. Run the four first. On a small app you may never need the rest.

Each one below has what to type, what must come out, and the way it usually breaks.

![Four search test cases on a list that holds "Sample item", "Sample report" and "Other thing". One: type "sample", two rows must come out and "Other thing" is gone. Two: type "zzqx", a sentence must say nothing matched. Three: empty the box, all three rows return. Four: pick a filter and type "sample", rows that pass both come out and the filter is still set.](https://everyrole.dev/s/blog/search-functionality-test-cases/four-cases.webp)

Four cases, three rows of test data. An honest note: our practice app has no search box, so this post’s pictures are drawn, not photographed.

## Test cases for search functionality need known data

Search test cases fail to mean anything when the data is unknown. “Search for a term and check results appear” passes on any list that isn’t empty.

So make three things with names you chose: `Sample item`, `Sample report`, `Other thing`. Two share a word, one doesn’t. Every case below is checked against those three, and you delete them afterwards.

## 1. A term with results

**Type:** `sample`

**Must come out:** exactly two rows, `Sample item` and `Sample report`. `Other thing` is not on the page.

Both halves count. A search that returns everything also “shows results for sample”. The row that must be absent is what makes this a test. It is the same rule as for any [expected result](https://everyrole.dev/blog/how-to-write-test-cases): name what must be there and what must not.

How it breaks: the search matches only from the start of the name, or only whole words, or only the first page of data. Or it is case sensitive and `sample` finds nothing while `Sample` finds two. Decide which behaviour you want and write it into the case.

## 2. A term with none

**Type:** `zzqx`, or any string you are sure is nowhere in your data.

**Must come out:** a sentence that says nothing matched, the term still in the box, and a way back to the full list.

This is the “no results test”, and it has more ways to go wrong than it looks:

- a blank area, with no words at all,
- a spinner that never stops, because the code waits for a first row,
- the full list, because an empty result fell back to “show all”,
- an error page, because something tried to read the first result of nothing.

![Two answers to the term "zzqx". The first is a search box over an empty white area. The second is the same search box over the sentence "No items match zzqx" and a link "Clear the search".](https://everyrole.dev/s/blog/search-functionality-test-cases/no-results.webp)

The blank answer can’t be told apart from a page that is still loading. The second one can be checked by a test, and understood by a person.

A blank area is the hard one for testing, because “no rows” is true of it. A check that only counts rows passes. That is [a hollow pass](https://everyrole.dev/blog/hollow-passes): the test has to look for the sentence.

## 3. Cleared

**Do:** after either search, empty the box (or press the clear control, if there is one).

**Must come out:** all three rows, in their usual order.

It sounds too simple to fail. It fails in two ways. Some searches treat the empty string as one more term and answer “nothing matched”. Others keep the last results on screen, because the code only searches when the box has text in it. Either way the person is stuck in a filtered view with an empty box and reloads the page.

Check the address too, if your search writes the term into it. After clearing, reloading the page must not bring the old term back.

## 4. A filter with the search

Skip this one if your list has no filter, sort or tab beside the search.

**Do:** pick a filter that leaves some rows out (say, “Reports only”). Then type `sample`.

**Must come out:** only rows that pass both, here `Sample report`. And the filter control still shows “Reports only”.

Then do it in the other order: type first, pick the filter second. The bug to look for is two controls that don’t know about each other. Typing resets the filter without saying so, or choosing a filter empties the box. The person thinks they are looking at reports that match “sample” and they are looking at everything that matches “sample”.

## Search test cases we leave for later

From the long lists, these are the ones we would add next, in order, when the four pass:

- **A space before or after the term.** People paste. ` sample ` should find what `sample` finds.
- **The term in another case**, if you didn’t settle that in case 1.
- **Enter instead of the button**, if the search has a button.
- **Back.** Search, open a result, press Back. Are the term and the results still there?

And the ones we don’t write as functional cases at all: every special character one by one, strings of thousands of characters, and injection strings. We’d expect little from the first two on a search box that passes the cases above. The third is a security test and deserves a proper one, not a line in a QA list.

## Search functionality testing by kind of user

One more column, if your app has more than one kind of user: who is searching. A search must never return a row the person couldn’t open from the list. Log in as the second user, search for a word you know is only in the first user’s data, and expect case 2’s answer. It is [the IDOR check](https://everyrole.dev/blog/idor-testing) arriving through a different door.

## How EveryRole runs search cases

EveryRole treats a search as its own kind of stop: a search field, or a form inside a search region. At that stop it runs two main cases every time, with the same names as above: **Term with results** and **Term with none**. Two extra cases are off until you turn them on: **Cleared**, and **Filter with search**, which applies where a filter sits beside the search.

For the term with results, the first answer is shown to you and waits for your yes. After that, every run compares with what you approved, so a search that starts returning everything comes back as “Result changed”.

It runs these on the live site, from outside, as the kind of user the journey belongs to, and the other kinds of user are checked at the stop, as at any stop. It doesn’t know what is in your database, so it can’t tell you a row is missing that should have matched. Your three rows of known data are still the best search test there is.

## Try it on your own app

EveryRole tests your app’s real user journeys for each kind of user, from the live site, and runs them after every deploy. Paste your app’s address to see what it finds.

[Start with your app](https://everyrole.dev/signup) [How it works](https://everyrole.dev/docs#start)

## Keep reading

Forms, uploads and downloads

### [CRUD test cases: create, edit, delete, then reload](https://everyrole.dev/blog/crud-test-cases)

CRUD testing in the browser, in nine cases. After each create, edit and delete, look where the thing lives and reload. A success message is not the outcome.

Nov 22, 2026  6 min read

Forms, uploads and downloads

### [File upload test cases: type, size, empty, name](https://everyrole.dev/blog/file-upload-test-cases)

Test cases for file upload, with seven small files to keep at hand. Wrong type, renamed type, empty, at and over the limit, an odd name, the same name twice.

Nov 22, 2026  6 min read

Forms, uploads and downloads

### [How to test a file download or a CSV export](https://everyrole.dev/blog/test-file-download)

How to test file download in four checks. A file arrived, it is the type the button names, it isn’t empty, and it holds the rows the page showed. Open the file.

Nov 22, 2026  6 min read
