How to Write Test Cases for Favorites (With Examples)

How to Write Test Cases for Favorites (With Examples) requires a systematic approach to ensure the feature functions robustly across various user interactions and data states. This guide will walk thr

March 29, 2026 · 16 min read · How-To Guides

How to Write Test Cases for Favorites (With Examples) requires a systematic approach to ensure the feature functions robustly across various user interactions and data states. This guide will walk through the anatomy of effective test cases, explore different testing categories like positive, negative, edge, and boundary conditions, and provide a comprehensive set of examples for a typical "favorites" functionality. We'll cover data setup, prioritization strategies, and how to link these cases back to requirements, ultimately demonstrating how a blend of meticulously designed test cases and autonomous testing can achieve superior coverage.

The "favorites" feature, seemingly simple, underpins user engagement in countless applications—from e-commerce wishlists and content bookmarking to social media likes and saved searches. Its reliability directly impacts user satisfaction and retention. A broken favorites mechanism leads to frustration, lost data, and ultimately, user churn. Therefore, writing high-signal test cases for favorites demands attention to detail, anticipating not just the happy path but also the myriad ways users might interact with or misuse the feature.

Understanding the Anatomy of a High-Signal Test Case

Before diving into specific examples, let's define what constitutes a well-structured test case. Each component serves a critical purpose in ensuring clarity, reproducibility, and comprehensive coverage.

Test Case ID and Title

A unique identifier (TC-FAV-001) allows for easy referencing, tracking, and reporting. The title should be concise yet descriptive, summarizing the test's objective (e.g., "Verify adding an item to favorites from product detail page").

Preconditions

These are the conditions that must be true *before* the test steps can be executed. They set the stage for the test. For a favorites feature, preconditions might include:

Test Steps

A sequential, unambiguous list of actions the tester must perform. Each step should be atomic and clearly state the expected interaction. Vague steps like "Click around" are unhelpful. Instead, use "Click 'Add to Favorites' button on Product A's detail page."

Expected Result

This is the observable outcome if the feature behaves correctly. It should be specific and measurable. For example, "Product A is displayed in the 'My Favorites' list and a success toast message appears." Avoid general statements like "It works."

Postconditions (Optional but Recommended)

Actions to clean up the test environment or revert changes made during the test, ensuring subsequent tests start from a known state (e.g., "Remove Product A from favorites").

Test Data

Any specific data required for the test (e.g., UserID: user123, ProductID: P001, Item Name: "Luxury Watch"). This ensures tests are repeatable regardless of changes in the underlying data.

Priority

A classification (e.g., High, Medium, Low) based on the feature's criticality, risk, and frequency of use. Core favorites functionality should always be High priority.

Traceability to Requirements

Linking the test case back to a specific requirement (e.g., REQ-FAV-001: Users shall be able to add/remove items from their favorites list) ensures that every requirement is tested and helps assess coverage.

Categories of Test Cases for Favorites

To achieve comprehensive coverage, test cases should span several categories, each designed to probe different aspects of the feature's behavior.

Positive Test Cases (Happy Path)

These verify that the feature works as intended under ideal conditions, following the expected user flow.

Negative Test Cases

These test how the system handles invalid input or unexpected user actions.

Edge/Boundary Test Cases

These focus on the limits of the system or unusual but valid conditions.

Data-Driven Test Cases

Testing with varying sets of data to ensure consistency and handle different data types or volumes.

Performance Test Cases

While often handled by dedicated performance testing, individual test cases can hint at potential bottlenecks.

Security Test Cases

Ensuring the favorites feature is secure.

Usability/Accessibility Test Cases

Though often broader, specific cases can be written.

Data Setup and Management for Favorites Testing

Effective testing of favorites relies heavily on well-prepared and consistent test data. This is often an overlooked aspect, leading to flaky tests or incomplete coverage.

Pre-populating Test Data

For most favorites scenarios, you'll need:

Test Data Management Strategies

  1. Database Seeding: For backend-driven applications, scripts (e.g., SQL, ORM migrations, custom Python/Node scripts) can populate the database with specific datasets before each test run or suite. This ensures a clean, predictable state.
  2. API Endpoints for Setup: If the application provides internal APIs for administrative tasks (e.g., adding users, creating items, managing favorites), these can be leveraged in test setup routines.
  3. UI-Driven Setup (for specific cases): While generally slower, some complex setup scenarios might require UI interactions, especially for end-to-end tests that mirror real user journeys. However, keep this to a minimum for efficiency.
  4. Test Data Factories: In automated testing frameworks, "factories" can generate synthetic data on demand, ensuring uniqueness and variety without manual intervention. For example, a FavoriteItemFactory could create an item with specific properties for a test.
  5. Environment Isolation: Use dedicated test environments. Never test against production data or environments. This prevents data corruption and ensures repeatable results.

Example: Test Data Preparation for a Favorites Feature

Let's say we're testing a product catalog's favorites feature.


# Example: Python script for setting up test data (conceptual)

from database_client import db
from models import User, Product, Favorite

def setup_favorites_test_data():
    # Clear existing test data for a clean slate
    db.clear_table(Favorite)
    db.clear_table(Product)
    db.clear_table(User)

    # Create test users
    user_john = User(username="john.doe", email="john@example.com", password="password")
    user_jane = User(username="jane.smith", email="jane@example.com", password="password")
    user_new = User(username="new.user", email="new@example.com", password="password")
    db.add_users([user_john, user_jane, user_new])

    # Create test products
    product_a = Product(name="Luxury Watch", description="High-end timepiece", price=1500.00, available=True, category="Electronics")
    product_b = Product(name="Vintage Camera", description="Classic film camera", price=300.00, available=True, category="Photography")
    product_c = Product(name="Out of Stock Item", description="Temporarily unavailable", price=50.00, available=False, category="Home Goods")
    product_d = Product(name="Special Chars!@#$", description="Item with special characters", price=10.00, available=True, category="Misc")
    product_e = Product(name="Very Long Product Name That Exceeds Typical Display Limits And Might Cause UI Issues If Not Handled Gracefully In The Front End", description="A product designed to test boundary conditions for text length.", price=99.99, available=True, category="Test")
    db.add_products([product_a, product_b, product_c, product_d, product_e])

    # Pre-populate favorites for 'john.doe'
    db.add_favorite(user_john, product_a)
    db.add_favorite(user_john, product_b)

    print("Test data for favorites feature has been set up.")

# Call this function before running your test suite
# setup_favorites_test_data()

This ensures that when you run TC-FAV-001: Verify adding an item to favorites from product detail page, product_a and product_b might already be favorited by john.doe, while product_c is out of stock, and new.user has an empty favorites list. This precision in data setup is crucial for reliable test execution.

Comprehensive Test Case Examples for Favorites

Here’s a table outlining a robust set of test cases for a typical "favorites" feature in an e-commerce or content platform. These examples cover various scenarios, from basic functionality to edge cases.

Test Case IDPriorityPreconditionsTest StepsExpected ResultTraceabilityNotes
Positive Cases
TC-FAV-001HighUser logged in. Product A exists and is not favorited.1. Navigate to Product A's detail page.
2. Click "Add to Favorites" button.
1. "Add to Favorites" button changes to "Favorited" (or similar).
2. Success message/toast appears.
3. Product A appears in "My Favorites" list.
REQ-FAV-001Basic add functionality.
TC-FAV-002HighUser logged in. Product A is in favorites.1. Navigate to "My Favorites" list.
2. Locate Product A.
3. Click "Remove from Favorites" button/icon next to Product A.
1. Product A is removed from "My Favorites" list.
2. Success message/toast appears.
3. "Add to Favorites" button on Product A's detail page reverts to original state.
REQ-FAV-002Basic remove functionality.
TC-FAV-003HighUser logged in. User has 3 items in favorites.1. Navigate to "My Favorites" list.1. All 3 favorited items are displayed correctly with their details (name, image, price).
2. List is paginated/scrollable if many items.
REQ-FAV-003View list functionality.
TC-FAV-004MediumUser logged in. Product A, B, C exist and are not favorited.1. Add Product A to favorites.
2. Add Product B to favorites.
3. Add Product C to favorites.
4. Navigate to "My Favorites" list.
1. All three products (A, B, C) are listed in "My Favorites".
2. Order of items is consistent (e.g., by addition date, alphabetical).
REQ-FAV-001, REQ-FAV-003Add multiple distinct items.
TC-FAV-005MediumUser logged in. Product A is favorited.1. Navigate to Product A's detail page.
2. Verify "Add to Favorites" button state.
1. Button is already in "Favorited" state (e.g., filled heart icon, text "Favorited").REQ-FAV-001Verify button state on item page.
TC-FAV-006MediumUser logged in. Product A is favorited.1. Navigate to Product A's detail page.
2. Click "Favorited" button to remove.
3. Navigate to "My Favorites" list.
1. Product A is removed from favorites.
2. "Favorited" button on Product A's detail page reverts.
3. Product A is no longer in "My Favorites" list.
REQ-FAV-002Remove from product detail page.
Negative Cases
TC-FAV-007HighUser *not* logged in. Product A exists.1. Navigate to Product A's detail page.
2. Click "Add to Favorites" button.
1. User is prompted to log in/register.
2. Product A is *not* added to favorites.
REQ-FAV-004Attempt to favorite as guest.
TC-FAV-008MediumUser logged in. Product A is *already* favorited.1. Navigate to Product A's detail page.
2. Click "Add to Favorites" button (which should be in a favorited state).
1. No new favorite entry is created.
2. No error message (or a message indicating it's already favorited).
3. Item count in favorites remains unchanged.
REQ-FAV-005Add already favorited item.
TC-FAV-009MediumUser logged in. Product A is *not* favorited.1. Navigate to "My Favorites" list (empty or other items).
2. Attempt to remove Product A (e.g., via API call or direct URL manipulation if possible).
1. Error message (e.g., "Item not found in favorites" or "Unauthorized operation").
2. No change to actual favorites list.
REQ-FAV-002Remove non-favorited item.
TC-FAV-010MediumUser logged in. Product X (non-existent)1. Attempt to add Product X to favorites (e.g., via API call mimicking UI action).1. Appropriate error message (e.g., "Product not found").
2. Product X is not added to favorites.
REQ-FAV-001Add non-existent item.
Edge/Boundary Cases
TC-FAV-011HighUser logged in. Favorites list is empty.1. Navigate to "My Favorites" list.1. "My Favorites" list displays a message like "Your favorites list is empty." or "Start adding items to your favorites."
2. No items are displayed.
REQ-FAV-003Empty favorites list.
TC-FAV-012MediumUser logged in. Max allowed favorites (e.g., 500 items).1. Add 499 unique items to favorites.
2. Attempt to add a 500th unique item.
3. Attempt to add a 501st unique item.
1. 500th item is added successfully.
2. 501st item addition attempt results in an error message (e.g., "Favorites limit reached").
REQ-FAV-006Max favorites limit.
TC-FAV-013MediumUser logged in. Product with extremely long name (e.g., Product E from data setup).1. Navigate to Product E's detail page.
2. Add Product E to favorites.
3. Navigate to "My Favorites" list.
1. Product E is successfully added.
2. Product E's name is displayed correctly in the list (e.g., truncated with ellipsis, wrapped).
3. UI layout is not broken.
REQ-FAV-001, REQ-FAV-003Long product name.
TC-FAV-014MediumUser logged in. Product with special characters in name (e.g., Product D).1. Navigate to Product D's detail page.
2. Add Product D to favorites.
3. Navigate to "My Favorites" list.
1. Product D is successfully added.
2. Product D's name (including special characters) is displayed correctly in the list.
3. No encoding issues.
REQ-FAV-001, REQ-FAV-003Special characters in name.
Data-Driven/State-Based Cases
TC-FAV-015MediumUser logged in. Product C (Out of Stock Item) exists.1. Navigate to Product C's detail page.
2. Add Product C to favorites.
3. Navigate to "My Favorites" list.
1. Product C is added to favorites.
2. In favorites list, Product C is clearly marked as "Out of Stock" or "Unavailable".
3. User cannot purchase/add to cart from favorites list (if applicable).
REQ-FAV-007Favorite out-of-stock item.
TC-FAV-016MediumUser logged in. Product A is favorited. Product A's price changes *after* being favorited.1. Verify Product A's original price in favorites list.
2. (Admin action) Change Product A's price in backend.
3. Refresh "My Favorites" list.
1. Product A's price in "My Favorites" list updates to the new price. (Or, if business logic dictates, shows original price with a "price changed" indicator).REQ-FAV-008Price change of favorited item.
TC-FAV-017MediumUser logged in. Product A is favorited. Product A is *deleted* from the catalog.1. Verify Product A is in favorites.
2. (Admin action) Delete Product A from catalog.
3. Refresh "My Favorites" list.
1. Product A is gracefully handled in favorites (e.g., marked "Deleted", "Unavailable", or automatically removed).
2. No broken links or errors.
REQ-FAV-009Deletion of favorited item.
User Experience/Accessibility Cases
TC-FAV-018LowUser logged in. Product A exists and is not favorited.1. Navigate to Product A's detail page using keyboard (Tab, Shift+Tab).
2. Use Space/Enter key to activate "Add to Favorites" button.
3. Navigate to "My Favorites" list using keyboard.
1. Keyboard focus navigates correctly to/from favorite button.
2. Button activates with keyboard.
3. Favorites list items are keyboard navigable.
REQ-FAV-010Keyboard navigation.
TC-FAV-019LowUser logged in. Product A exists and is not favorited. Screen reader enabled.1. Navigate to Product A's detail page.
2. Activate "Add to Favorites" button.
1. Screen reader announces "Add to Favorites button" clearly.
2. Upon clicking, screen reader announces "Product A added to favorites" or similar feedback.
3. Button state change is announced (e.g., "Favorited button").
REQ-FAV-011Screen reader compatibility.
Concurrency/Race Conditions
TC-FAV-020MediumUser logged in. Product A not favorited.1. User 1: Clicks "Add to Favorites" for Product A.
2. User 2: Clicks "Add to Favorites" for Product A *simultaneously* (e.g., two tabs, different devices).
1. Product A is added to favorites *only once* for the user.
2. No duplicate entries.
3. Both UI instances reflect the favorited state correctly.
REQ-FAV-012Concurrent add.
TC-FAV-021MediumUser logged in. Product A is favorited.1. User 1: Clicks "Remove from Favorites" for Product A.
2. User 2: Clicks "Remove from Favorites" for Product A *simultaneously*.
1. Product A is removed from favorites *only once*.
2. Both UI instances reflect the non-favorited state correctly.
REQ-FAV-013Concurrent remove.

This table provides a solid foundation. Remember to adapt the specific preconditions, steps, and expected results to your application's exact behavior and UI.

Prioritization and Traceability to Requirements

Effective test management isn't just about writing test cases; it's also about strategically prioritizing them and ensuring they align with product requirements.

Prioritization Strategies

Prioritizing test cases helps focus efforts on the most critical functionality, especially when time or resources are limited. Common factors influencing priority:

  1. Business Criticality: How important is the favorites feature to the core business? Is it a primary revenue driver or a secondary engagement tool?
  2. Frequency of Use: How often do users interact with the favorites feature? High-usage paths warrant higher priority.
  3. Risk of Failure: What's the impact if the feature breaks? Data loss, monetary loss, reputational damage, or minor inconvenience?
  4. Dependencies: Does the favorites feature rely on other modules? Tests for critical dependencies might have higher priority.
  5. Complexity: More complex logic often requires more thorough testing.
  6. New vs. Existing Functionality: New features usually get higher priority testing to uncover initial bugs.

A simple High/Medium/Low scale is often sufficient, as shown in the examples. For example, "Add to Favorites" and "Remove from Favorites" are almost always High priority because they represent the core actions. Viewing an empty list might be High if it's a common initial state for new users, but perhaps Medium if the app typically pre-populates some content.

Traceability Matrix

A traceability matrix links requirements to test cases (and often to defects and code as well). This ensures:

A simplified traceability matrix might look like this:

Requirement IDRequirement DescriptionTest Case IDs
REQ-FAV-001Users shall be able to add an item to their favorites list.TC-FAV-001, TC-FAV-004, TC-FAV-008, TC-FAV-010, TC-FAV-013, TC-FAV-014, TC-FAV-015
REQ-FAV-002Users shall be able to remove an item from their favorites list.TC-FAV-002, TC-FAV-006, TC-FAV-009
REQ-FAV-003Users shall be able to view their complete favorites list.TC-FAV-003, TC-FAV-004, TC-FAV-011, TC-FAV-013, TC-FAV-014, TC-FAV-015, TC-FAV-016, TC-FAV-017
REQ-FAV-004Guests attempting to favorite an item shall be prompted to log in/register.TC-FAV-007
REQ-FAV-005Users cannot add an item to favorites if it is already in their list.TC-FAV-008
REQ-FAV-006The system shall support a maximum of 500 items in a user's favorites list.TC-FAV-012
REQ-FAV-007Favorited items that are out of stock shall be clearly indicated in the favorites list.TC-FAV-015
REQ-FAV-008Price changes for favorited items shall be reflected in the favorites list.TC-FAV-016
REQ-FAV-009Deleted catalog items shall be gracefully handled in the favorites list.TC-FAV-017
REQ-FAV-010The favorites feature shall be fully navigable via keyboard.TC-FAV-018
REQ-FAV-011The favorites feature shall be compatible with screen readers.TC-FAV-019
REQ-FAV-012Concurrent attempts to favorite the same item by the same user shall result in a single entry.TC-FAV-020
REQ-FAV-013Concurrent attempts to remove the same item from favorites by the same user shall result in a single removal.TC-FAV-021

This matrix clearly shows which test cases cover which requirements, highlighting any gaps.

Manual vs. Automated Testing for Favorites

Both manual and automated testing have their place in ensuring the quality of a favorites feature.

Manual Testing

Advantages:

Disadvantages:

Automated Testing

Advantages:

Disadvantages:

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free