How to Write Test Cases for Search Functionality: Your Ultimate Guide with 24 FREE Examples to get you started

Test cases for search functionality featured image

To write a test case for search functionality, establish the purpose of the search feature. Is it internal or external? Consider testing autosuggest, filters and operators where required. Ensure the results are accurate. As usual you should always consider positive and negative scenarios too.

As human beings, we are very curious creatures.

We want to learn new things all the time.

Gaining knowledge is part of our DNA.

Growing up as a kid in London, I used to go to something called a ‘library’ to find information.

<sarcasm> It was a place where you would find books </sarcasm>

It was laborious and you never were guaranteed to find what you were looking for.

However since the arrival of the internet, access to information has become a lot more accessible, easier and much quicker.

What used to take days or weeks can literally be found in seconds.

Organisations such as Google have become Trillion Dollar companies who started with a simple concept of ‘Search’.

In this article I’m going to give you test cases for search functionality to help you with your software testing journey.

Where would you use search functionality?

I could go on all day as the uses are vast.

Look around you.

Apart from the obvious, I bet there are lots of things that use some kind of search functionality that you may be unaware of.

Your cell/mobile phone has a search feature.

Your smart TV and it’s Apps may have a search feature.  Just look at ‘Amazon Video’, ‘Netflix or BBC iPlayer.

In fact my old BT cordless telephone also has a search feature.  It’s very basic but it still does the job.

Search just isn’t limited to visual or textual entry but has now evolved into “voice search”.  

Amazon’s Alexa and Google voice assistant are great examples of how this technology works.

Maybe if you want to book a hotel or download an app then this all requires a type of search feature.

From an organisational perspective, your intranet, internet and web applications might be something you want to validate the search functionality for.

Learn How to Write Test Cases that Your Grandparent Can Run

Context and Background

As always, I like to set a context around what we are going to test.  

For the sake of this article, let’s use search functionality that uses a ‘search filter’ on an eCommerce website.

These are common features that have a broad range of uses.

You can also use these for an intranet, website search feature and more. 

I just want to narrow it down so its easier to understand.

Positive Test Cases for Search Functionality 

  1. Verify search box is displayed as expected
  2. Verify that the search button is displayed as expected
  3. Verify all UI elements of the search functionality are displayed including fonts.
  4. Verify cursor is ‘in focus’ by default inside the search box. 
  5. Click submit button when no search criteria is entered
  6. Enter more than the maximum number of characters allowed
  7. Verify that when a user types a query, the system generates auto suggestions as you type.

Note: Some organisations may prefer this option as this may have an impact on SEO.

  1. Verify entering a single character and clicking submit returns result(s) or not found page.
  2. Verify entering a special character and clicking submit returns a “not found” page.

In your test data, you can include a special character in the pages you are testing, for example an exclamation mark “!” and see if it returns.

  1. Verify entering numbers and clicking submit returns a result or nor found page
  2. Verify entering spaces at the beginning of the search query are ignored
  3. Validate pagination feature works when more than 1 page of results is displayed when there are more results returned.
  4. Verify user can toggle between how many results they want to see
  5. Validate results page displays page titles, descriptions and hyperlinks (this is NOT a test for relevancy of results) 
  6. Verify when user enters a query where no results exist, the results page displays a meaningful alert message such as “Cannot find <query>, please try another query”. 
  7. Validate results displayed are relevant to the user’s search query.
    • Note: This can be a series of complex tests if you are testing the algorithm.
  8. On the results page, verify the user can sort how they want to see the results of their query (e.g. Featured, Newest, highest price, lowest etc).

Negative Test cases for Search Functionality 

  1. Verify no results are returned when the user enters no value and clicks on the ‘Search’ button.  
  2. Verify System does not allow drag and drop of various file types into the search field 

Test Cases Using Search Operators

Many search engine style web applications allow search operators.  This means you can really refine your search to be quite specific.

Google as well as many search engines  have a number of search operators that you can use.  

  1. Verify Exact Match Search
  2. Verify Phrase match
  3. Verify Broad match

Advanced Search Functionality

Some of you may be aware that search engines like Google and Bing have advanced search features that can allow you to really dig deeper when looking for something specific.

With eCommerce sites, I’ve found that you generally don;t need an advanced search filter.

I guess there is a commercial reason for this but I haven’t seen this on most of the top eCommerce sites.

Advanced search functionality

Testing Search Filters

Search filters differ slightly from search operators.

Search filters are quite commonplace for eCommerce websites where the search result will be based on the criteria you have selected.

The best way to test the filers is to ensure that every item returned falls within the search criteria.

Also be mindful of any business rules that may need to be implemented.

For example, the search results may be slightly more flexible if the exact criteria is not met.

Always check your requirements.

Let’s take a look at the Curry’s website.  They are a UK based retailer.

Search filters image

From the ‘Gaming Laptops’ section, when no search filters are selected there are 96 laptops that are displayed.

We can create a list of test scenarios that can check different filters.

For example

Test Scenario 1 – Find a gaming laptop under £1500 that has an  Intel I7 CPU, 1 TB SSD hard drive, 16 GB RAM and a minimum NVIDIA RTX 3060 GPU and a 17 inch screen.  

Below is the search result screenshot.  

Let me know if you think it’s a good result or not and why?

search filters results page

Depending on how strict your search criteria is, all results that are displayed should adhere to each criterion.

If no results are found then the system should return this and let the user know.

I suspect because this is an eCommerce platform and sales is the name of the game, the tolerance levels will not be as strict and products that are slightly outside the criteria will be displayed.

I would guess that’s your real world equivalent of upselling.

Just be mindful of your organisation’s requirements and think outside the box a little.

Autocomplete Functionality 

Search engines, eCommerce and intranet sites are just a few of the types of sites that will feature some kind of autocomplete or autosuggest

For an eCommerce site, when a user types a search phrase, you’re likely to see a mix of relevant search phrases as well as relevant products based on the query.

For search engines like Google, it will use the autosuggest query to give you an idea of relevant terms that are popular.

Using an intranet search such as Microsoft SharePoint, I have found that the search will expand to people, contacts, intranet pages and also organisation wide shared documents.

  1. Verify search box displays autocomplete/autosuggest

Don’t Forget Security Testing for Search Functionality

If your search feature allows users from the outside world to use this functionality, don’t forget to get your Penetration testing team to test this fully. 

  1. Validate pen test for search box.

I’ve only added 1 test case here to get on your radar. 

However you will want to break this down further to cover SQL injections, cross site forgeries and a whole host of other Pen tests to ensure your search box is safe from outside attack.

You should add this item to your test plan or at least ask the question if this needs to be security tested?

In many places where i have worked, the QA team did not have the capability to conduct Pen testing as that is a specialist skill.

As a result, it was either passed onto the IT security team or outsourced to a trusted partner.

Don’t forget Testing the Boundaries

If you want to really test a search algorithm then search functionality is a great place to conduct boundary value analysis.  

I would consider exactly WHAT constitutes a result being displayed and not.  From there you should be able to set your weightings accordingly to understand whether it will or will not appear.

Depending on the use of the feature it can be quite tricky if your requirements are very specific but its a fun thing to test.

Cross Browser Testing

It’s funny how web applications can behave on various platforms, operating systems and browsers.

Ensure that you test the search functionality across a variety of the most popular browsers. 

My approach in mitigating browser compatibility risks is to find out the top browsers that generate the most traffic/revenue and test these first.

Not testing this properly may result in lost sales and traffic.

Add to Your Regression Testing Suite for Future Test Execution

Remember that you can use the multiple test cases you’ve created and add them to your test pack.

This is especially useful when you are testing changes or upgrades.

Summary

When you think about testing search functionality, it can become quite complicated.

As a tester these are precisely the kinds of challenges we look forward to.

In fact, if you like functional testing with lots of business rules, you might just enjoy it.