Course contentsShow
← Computer Science
Lesson 2219 of 2,87250. Software TestingFree lesson

Test Cases and Test Suites

Defining test cases with inputs, expected outputs, and organizing them into test suites.

Test Cases and Test Suites

You'll learn: How to formally structure individual tests and organize them into cohesive collections for systematic software validation.

What Is a Test Case?

A test case is a single, specific scenario designed to verify a piece of software behavior. Think of it like a recipe card in cooking: each card lists precise ingredients (inputs), exact steps (execution), and what the dish should look like when done (expected output).

Every test case has three essential components:

  1. Inputs: The data or conditions fed to the code
  2. Expected Output: What correct behavior should produce
  3. Actual Output: What the code actually returns (compared against expected)

For example, testing a calculateDiscount function:

  • Input: price = 100, discount_percent = 20
  • Expected Output: 80
  • Actual Output: (run the function to see)

If actual matches expected, the test passes. If not, it fails, revealing a defect.

What Is a Test Suite?

A test suite is an organized collection of related test cases grouped together for execution. Like organizing recipe cards into categories (appetizers, desserts), test suites group tests by feature, module, or purpose.

Benefits of test suites:

  • Run all related tests with one command
  • Track which features are well-tested
  • Report overall pass/fail statistics
  • Enable automation and continuous testing

Think of a test suite as a quality checklist: each test case verifies one requirement, and the suite ensures nothing is forgotten.

Example Structure

A login feature test suite might contain:

  • Test case 1: Valid credentials → successful login
  • Test case 2: Wrong password → error message
  • Test case 3: Empty username → validation error
  • Test case 4: SQL injection attempt → blocked access

Key Takeaway: Test cases define specific input-output scenarios that validate correctness, while test suites organize these cases into manageable, executable collections for comprehensive software verification.