Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

program-testing-and-debugging-kiHLkLdx

The document covers program testing and debugging, focusing on exhaustive and boundary testing methods, as well as debugging techniques. It outlines the importance of unit testing to handle user inputs and the process of debugging to isolate and resolve software issues. Additionally, it discusses the use of Integrated Development Environments (IDEs) and debuggers to facilitate code writing, execution, and problem-solving.

Uploaded by

analindatoh.at
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

program-testing-and-debugging-kiHLkLdx

The document covers program testing and debugging, focusing on exhaustive and boundary testing methods, as well as debugging techniques. It outlines the importance of unit testing to handle user inputs and the process of debugging to isolate and resolve software issues. Additionally, it discusses the use of Integrated Development Environments (IDEs) and debuggers to facilitate code writing, execution, and problem-solving.

Uploaded by

analindatoh.at
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

Program testing and debugging

1.Learning Outcomes

2. Overview

3. EXH AUSTIVE AN D B OUN DAR Y TESTIN G (25 MIN S)

3.1 Exhaustive testing

3.2 Boundary testing

3.3 Knowledge Check

4. DEB UGGIN G (35 MIN S)

4.1 What is Debugging

4.2 IDE and Debugger

4.3 Knowledge Check

R EVIEW QUESTION S (5 MIN S)

Review Questions
Lesson 1 of 9

1.Learning Outcomes

At the end of the topic, you should be able to

explain the di erences between exhaustive and boundary


testing during Unit testing
analyse and use suitable debugging techniques to solve
bugs

use a debugger to trace through program execution to


isolate problems
Lesson 2 of 9

2. Overview

Why do we need to know about testing and debugging?


Have you encountered using a software and it hangs or gives you an unexpected output? That
may be because the software did not handle some user input correctly. In order to reduce
such encounters, the programmer needs to perform unit testing on their software to handle
all possible user inputs appropriately. If the software is not behaving correctly, the
programmer will need to perform debugging to isolate and eradicate the cause.
Lesson 3 of 9

3.1 Exhaustive testing

WH AT I S E X H A UST I V E T E ST I N G? E X A MPL E I L L UST R AT I O N

Exhaustive testing is a test approach in which all combinations of inputs and preconditions are
used to test a software.

Most of the time, it is not feasible to perform exhaustive testing as the possible permutation of
inputs may be too large. It is very time consuming and tedious to test through all the possible
inputs. It may also be a challenge to anticipate all possible inputs and preconditions that may
occur.

WH AT I S E X H A UST I V E T E ST I N G? E X A MPL E I L L UST R AT I O N

Given a test which consists of 10 MCQs with a passing mark 0f 50. Each MCQ carries 10 marks.
A software is written to determine whether a particular student passed or failed the test. The
software accepts the input of the student's MCQ test mark and display whether the student has
passed or failed the test.

An example of exhaustive testing would be to test all the possible marks a student may get in
the MCQ test. The following video illustrates all the test inputs being fed into the software to
evaluate the result.
Lesson 4 of 9

3.2 Boundary testing

WH AT I S B O UN DA R Y T E ST I N G? E X A MPL E I L L UST R AT I O N B O UN DA R Y I N PUT S

Boundary testing is a test approach in which test inputs are generated using

the minimum and maximum input values

the corner values that would cause a change in the outcome

Boundary testing is used to test all the designed software ow of execution. The inputs are used
to evaluate whether the software is owing as intended and executing correctly.

WH AT I S B O UN DA R Y T E ST I N G? E X A MPL E I L L UST R AT I O N B O UN DA R Y I N PUT S

Using the same MCQ test example illustration in Exhaustive testing, instead of using all the
possible inputs to test, Boundary testing make use of lesser inputs to test all the designed
software ow of execution.

The following video illustrates boundary test inputs being fed into the software to evaluate the
result.
WH AT I S B O UN DA R Y T E ST I N G? E X A MPL E I L L UST R AT I O N B O UN DA R Y I N PUT S

In the example, the maximum mark possible is 100 and the minimum mark is 0. Thus 100 and
0 are part of the boundary input values.

The passing mark is 50 and this value is at the boundary where the outcome may change from
Pass or Fail. Corner values are the values near to 50 which will result in di erent outcomes. So
50 and 40 are all called the corner values. 50 will result in the outcome Pass and 40 will result
in the outcome Fail.
Exercise
Given a simple software that computes the price of an item. It rst prompts the user for the
day of week and then computes the price to pay.

Click on the SoloLearn "BoundaryTest" below. Analyse and test the codes there. What is the
boundary values to be used to test this software?
BoundaryTest
Check out what Roy has created on SoloLearn
READ MORE SOLOLEARN 

Click to view the answer and verify you've got it correctly



Boundary inputs:
1, 5, 6, 7

1 - Minimum value
5 - Corner value
6 - Corner value
7 - Maximum value
Lesson 5 of 9

3.3 Knowledge Check

True

Exhaustive testing uses all Boundary testing used


combinations of inputs and maximum, minimum and
preconditions for test corner values as test inputs

False

Exhaustive testing is a Boundary testing does not


feasible and commonly used test all the designed software
test approach ow of execution
Lesson 6 of 9

4.1 What is Debugging

What is debugging?
Debugging is a process of tracing software problems to isolate the cause and resolving the
problem.

A software that is giving a wrong outcome or behaving incorrectly is said to be having a bug.
That is why when a software programmer is trying to solve the problem, he is deemed to be
trying to remove the bug which give rise to the term debug.
There are various debugging techniques which may be used depending on circumstances.

Trace Messages

Log les

Debugger

We shall discuss more on the debugger in the next section.


Lesson 7 of 9

4.2 IDE and Debugger

What is an IDE
An integrated development environment (IDE) is a software used by a programmer to

write codes

run the codes to see the output

debug the codes when there is problem


There are many di erent IDEs (Eg. Pycharm, Eclipse and etc) available in the market for the
software programmer to choose. They generally o er similar basic functionalities may di er
in the following aspects

Visual look and feel

Way to operate

Additional features

Debugger
A debugger is a tool within the IDE that a software programmer can use to trace their
program execution. A debugger can be used to understand how a program ow (written by
other programmer) or to isolate a software bug.

A software programmer can choose to run the codes in normal mode or debug mode. When
there are some software bugs, the programmer can run in debug mode to use the debugger.

A debugger usually support these few basic features

Breakpoints

Single Stepping

Watches
Breakpoint
A breakpoint is a point in the codes where the debugger will pause to allow the programmer
to trace and investigate on a software bug.

The programmer can set one or multiple breakpoints within the codes to investigate what's
wrong with the program.
Single Stepping
A debugger allows the programmer to trace the program code execution line by line. This is
known as single stepping the program.
Single stepping is useful for the programmer to trace the status of the variables to isolate the
cause of a software bug.

Step-Over and Step-Into

There are 2 Single Stepping commands to run the code line by line.

Step-Over : Step through code line by line. If a line of code calls a


function, it will just show results returned by the function.

Step-Into : Step through code line by line. If a line of code calls a


function, it will jump to the code in the function and step through the
codes inside line by line.

Watch
A watch allows the programmer to keep watch of the value of selected variable and/or
expression.
The programmer can add multiple watches to keep various variables in view during code
execution to isolate on cause of a bug.

PyCharm Debugger
This section shows videos on how to use the debugger from the PyCharm (IDE). After looking
at the video, you may also want to follow the steps here to familirise with the debugger.

I N T R O DUC T I O N T O DE B UGGE R WO R K I N G T H R O UGH A N E X A MPL E

The following YouTube video shows you how to

go to debug mode

add a breakpoint

single step

add a watch

PyCharm Tutorial - 7. Debug python code using PyCharm


I N T R O DUC T I O N T O DE B UGGE R WO R K I N G T H R O UGH A N E X A MPL E

This video illustrate using a debugger through a program dealing with prime numbers.

Debugging with PyCharm Edu

Debug Exercise 1
Type the following codes at the IDE.
base = 5;
height = 10;
half = 1//2;
areaOfTriangle = half * base * height;
print("Area of our triangle is ",areaOfTriangle)
# expected output should be
# Area of our triangle is 25.0

Debug program 01

The expected output should show Area of our triangle is 25.0 but there is a bug in the codes.
Use Breakpoints and Single Stepping to nd out the problem and solve it.

Debug Exercise 2
Type the following codes at the IDE.

totalSecs = 128
mins = totalSecs / 60
secs = 128 - mins * 60
print(" 128 secs = ",mins ," mins ", secs," secs")
# expected output should be
# 128 secs = 2 mins 8 secs

Debug program 02

The expected output should show 128 secs = 2 mins 8 secs but there is a bug in the codes.
Use Breakpoints and Single Stepping to nd out the problem and solve it.
Lesson 8 of 9

4.3 Knowledge Check


Lesson 9 of 9

Review Questions
Question

01/10

Which of the following is not a reason for you to perform unit testing?

To verify all possible user inputs are handled appropriately

To ensure the software doesn't give user unexpected output

To have software quality to build up user's con dence

To let user perform debugging of the codes


Question

02/10

Which of the following is not true about Exhaustive testing?

It is a test approach in which all combinations of inputs and


preconditions are used to test a software

It is not feasible to perform exhaustive testing as the possible


permutation of inputs may be too large

It is the most feasible test approach we should use to perform all


unit testings

It is usually too time consuming and tedious to perform


Exhaustive testing
Question

03/10

Which of the following is not true about Boundary testing?

It is a type of Exhaustive testing

It is used to test all the designed software ow of execution

It's test inputs are generated using the minimum and maximum
input values

It's test inputs are generated using the corner values that would
cause a change in the outcome
Question

04/10

Which of the following is not true about debugging?

Debugging can only be performed by using a debugger

Debugging may be performed by adding trace messages to trace


program execution

Debugging may be performed by adding Log les to trace


program execution

It is a process of tracing software problems to isolate the cause


and resolving the problem
Question

05/10

What of the following cannot be done using an IDE?

Gather user requirements of the codes

Write codes

Run the codes to see the output

Debug the codes when there is problem


Question

06/10

Which of the following is not a basic functionality of a debugger?

Breakpoint

Single Stepping

Watches

Generate test reports


Question

07/10

_____ is a point in the codes where the debugger will pause to allow the
programmer to trace and investigate on a software bug.

IDE

Breakpoint

Single Stepping

Watch
Question

08/10

_____ is a feature that allows the programmer to trace the program code
execution line by line.

IDE

Breakpoint

Single Stepping

Watch
Question

09/10

_____ is a feature that allows the programmer to keep monitor the value of
selected variable and/or expression.

IDE

Breakpoint

Single Stepping

Watch
Question

10/10

Give a reason in which you will need to use Step-Into instead of Step-Over
during Single Stepping?

To trace the program code execution line by line

To monitor the value of selected variable and/or expression

To jump to the code in a function and step through the codes


inside

To pause to allow the programmer to trace and investigate on a


software bug

You might also like