Computer Science Grade 5 20 min

Testing Parts Separately

Testing Parts Separately

Tutorial Preview

1

Introduction & Learning Objectives

Learning Objectives Explain why testing small parts of a program individually is better than testing the whole program at once. Identify the different 'parts' or 'chunks' of a simple program. Define a specific input and predict the expected output for a single part of a program. Run a test on a single part of a program and compare the actual output to their prediction. Use the results of separate tests to find a bug in a larger program. Describe what a 'unit test' is in simple terms. Have you ever built a big LEGO set and realized at the end that you put a piece in backwards on the very first step? 😱 Let's learn how to check our work as we go! In this lesson, we will learn how to find and fix mistakes (called 'bugs') in our code...
2

Key Concepts & Vocabulary

TermDefinitionExample Problem DecompositionThe process of breaking down a large, complex problem into smaller, more manageable parts.If the problem is 'make a peanut butter and jelly sandwich,' the parts are: get the bread, get the peanut butter, spread the peanut butter, get the jelly, spread the jelly, and put the bread together. Unit TestA test for one single, small part (a 'unit') of your code to see if it works correctly on its own.In a calculator program, a unit test would be to check if the 'add' function works by giving it 2 and 3 and seeing if it returns 5. BugAn error or mistake in a computer program that stops it from working the way it should.You write code to add two numbers, but it subtracts them instead. That's a bug! InputThe information...
3

Core Syntax & Patterns

Isolate and Test Pattern Focus on one small piece of code. Run only that piece and ignore the rest of the program for the test. Use this when you want to be sure a specific function or block of code is working perfectly before you connect it to other parts. It helps you pinpoint exactly where a problem is. Predict, Run, Compare Pattern 1. Predict: What should the output be for your input? 2. Run: Execute the code with your input. 3. Compare: Does the actual output match your prediction? This is the fundamental process for every single test you perform. If the actual output doesn't match your prediction, you've found a bug!

4 more steps in this tutorial

Sign up free to access the complete tutorial with worked examples and practice.

Sign Up Free to Continue

Sample Practice Questions

Challenging
A program has two parts that are tested separately and both work perfectly. Part 1 calculates a 10% discount. Part 2 adds 5% sales tax. When the whole program runs, the final price is wrong. What is the most likely cause of the problem?
A.The computer's math chip is broken.
B.The way the two parts are connected and share data is wrong.
C.One of the tests must have been wrong.
D.The user entered the wrong starting price.
Challenging
A game program has a bug. The final score is calculated correctly, but a 'Level Up!' message that should appear for scores over 500 never shows up. The program has three parts: `Part A` calculates points, `Part B` adds them to the total score, and `Part C` checks the score and displays the message. Which part should you test first?
A.Part A, to make sure the points are right.
B.Part B, to make sure the total is right.
C.Part C, because it is responsible for the message that is missing.
D.Test all three at the same time.
Challenging
You are planning to write a program that draws a smiley face (a circle for the head, two dots for eyes, and an arc for the mouth). Following the idea of problem decomposition, what would be two good unit tests to plan?
A.Test drawing a circle for the head; Test drawing a dot for an eye.
B.Test the whole smiley face with a yellow color; Test it with a blue color.
C.Test if the program starts; Test if the program stops.
D.Test the program on a fast computer; Test it on a slow computer.

Want to practice and check your answers?

Sign up to access all questions with instant feedback, explanations, and progress tracking.

Start Practicing Free

More from Problem Decomposition

Ready to find your learning gaps?

Take a free diagnostic test and get a personalized learning plan in minutes.