Testing

Software Design
process

Also known as: software testing, test cases

Grade 6-8

View on concept map

Systematically running a program with known inputs to verify that its outputs are correct. Quality software requires thorough, systematic testing because bugs found early cost far less to fix.

Definition

Systematically running a program with known inputs to verify that its outputs are correct. Testing involves designing test cases that cover normal inputs, boundary values, and error conditions, then comparing actual results against expected results.

💡 Intuition

Try to break it before users do. Test normal cases, edge cases, and error cases.

🎯 Core Idea

Testing can prove that bugs exist, but cannot prove that no bugs remain—exhaustive testing is impossible.

Example

Test divide function with: (10, 2), (0, 5), (-6, 3), (5, 0) [error case].

Formula

\text{test passes} \iff o_e = o_a

🌟 Why It Matters

Quality software requires thorough, systematic testing because bugs found early cost far less to fix. Professional software teams typically write more test code than production code, and automated testing catches regressions before they reach users.

💭 Hint When Stuck

When writing test cases, cover three categories: typical inputs (normal use), boundary values (edges like 0, empty strings, maximum values), and error cases (invalid input that should be rejected gracefully). For each test, define the input, the expected output, and compare it to the actual output.

Formal View

A test case is a triple (i, o_e, o_a) where i is the input, o_e is the expected output, and o_a is the actual output. The test passes iff o_e = o_a. A test suite \{T_1, T_2, \ldots, T_m\} aims to cover all execution paths.

🚧 Common Stuck Point

Test edge cases: empty input, zero, maximum values, unexpected types.

⚠️ Common Mistakes

  • Only testing the happy path (normal inputs) and neglecting edge cases and error conditions
  • Writing tests that depend on each other's execution order instead of being independent
  • Assuming that passing all tests means the program is bug-free—testing can only show the presence of bugs, not their absence

Common Mistakes Guides

Frequently Asked Questions

What is Testing in CS Thinking?

Systematically running a program with known inputs to verify that its outputs are correct. Testing involves designing test cases that cover normal inputs, boundary values, and error conditions, then comparing actual results against expected results.

What is the Testing formula?

\text{test passes} \iff o_e = o_a

When do you use Testing?

When writing test cases, cover three categories: typical inputs (normal use), boundary values (edges like 0, empty strings, maximum values), and error cases (invalid input that should be rejected gracefully). For each test, define the input, the expected output, and compare it to the actual output.

How Testing Connects to Other Ideas

To understand testing, you should first be comfortable with algorithm and debugging. Once you have a solid grasp of testing, you can move on to unit testing and edge cases.

💻 Animated Visualization Animated

Test cases verify the code works correctly