Testing
Tests check that code works as expected.
About this topic
Testing checks that a program works correctly and meets its requirements. Test cases list an input and the expected output, then compare with the actual result. Good testing includes normal data, boundary data at the edges of valid ranges, and invalid or erroneous data that should be rejected.
Levels include unit tests for single functions, integration tests for parts working together, and system and user acceptance tests for the whole product. Automated tests can be run again after every change, called regression testing, to make sure new code did not break old features. Some teams write tests first, a practice called test-driven development.
For a function that accepts ages 13 to 18, test 15 as normal, 13 and 18 as boundary, 12 and 19 just outside, and the word cat as invalid. Testing can show that bugs exist but cannot prove there are none. Software failures in aircraft, medical devices and banking show why careful testing matters. A common misconception is that testing is done at the end; it works best from the start. Plan tests before writing code.
Key ideas
- Unit tests
- Edge cases
- Test-driven development
Quick check
Use cases: where Testing helps
- Homework: review the key idea behind Testing before you start a problem set.
- Exam revision: use the quick check to test whether you can recall Testing without notes.
- Visual learning: play with the interactive lab to see how Testing changes when you adjust its inputs.
- Teaching a friend: explain Testing in your own words, then compare your version with the key ideas.
Computing ideas run phones, search engines, games and the wider internet.
Frequently asked questions
What is Testing?
Tests check that code works as expected.
What will I learn in Testing?
Unit tests. Edge cases. Test-driven development.
Is Testing part of Computer Science?
Yes. It is one of 80 Computer Science topics on LearnViz HighSchoolEdu, with 3 key ideas, a live animation and a quick check.
Does the Testing lab work on a phone or tablet?
Yes. The animation resizes to fit your screen and supports touch, so you can drag, tap and slide with your finger.
How should I study Testing?
Read the summary and key ideas first, play with the interactive lab to see the idea in motion, then answer the quick check. If you get a question wrong, go back to the key idea it tests.
Do I need an account, and is my progress saved?
No account is needed. Marking a topic as learned is saved in your own browser, so it stays on that device and is not sent to a server.