- Home
- /
- Computational Thinking
- /
- Software Design & Development
- /
- Unit Testing
Unit Testing
Also known as: unit tests, automated unit tests
Grade 9-12
View on concept mapUnit testing is the practice of testing the smallest useful parts of a program, such as a single function or module, in isolation. Unit testing supports maintenance, debugging, and teamwork.
Definition
Unit testing is the practice of testing the smallest useful parts of a program, such as a single function or module, in isolation. A unit test gives known input, checks the output, and helps confirm that the unit still behaves correctly after changes.
๐ก Intuition
Instead of testing the whole machine at once, test each small part separately so failures are easier to find.
๐ฏ Core Idea
Small automatic checks make code safer to change.
Example
Formula
๐ Why It Matters
Unit testing supports maintenance, debugging, and teamwork. It catches regressions early and gives students a disciplined way to confirm that code still works after edits.
๐ญ Hint When Stuck
Pick one function, choose one clear input, write the expected output first, and then run the function to compare the actual result. Add edge cases after the basic test passes.
Formal View
Related Concepts
๐ง Common Stuck Point
A unit test should focus on one behavior at a time. If it depends on half the program, it is no longer a small isolated test.
โ ๏ธ Common Mistakes
- Writing tests that depend on external state instead of isolating the unit
- Combining many behaviors into one large test so failures are hard to diagnose
- Updating production code without rerunning the unit tests
Common Mistakes Guides
Frequently Asked Questions
What is Unit Testing in CS Thinking?
Unit testing is the practice of testing the smallest useful parts of a program, such as a single function or module, in isolation. A unit test gives known input, checks the output, and helps confirm that the unit still behaves correctly after changes.
What is the Unit Testing formula?
When do you use Unit Testing?
Pick one function, choose one clear input, write the expected output first, and then run the function to compare the actual result. Add edge cases after the basic test passes.
Prerequisites
Next Steps
How Unit Testing Connects to Other Ideas
To understand unit testing, you should first be comfortable with testing, function and edge cases. Once you have a solid grasp of unit testing, you can move on to version control.