Debugging and Program Testing
Debugging and Program Testing
FACULTY OF ENGINEERING
DATE: 1ST/08/2022
1
PROGRAMMING
Computer programming is the process of writing a code or set of instructions to be interpreted
and executed by a computer or another electronics device.
Computer program
A computer program is a sequence of instructions that a computer can interpret and execute.
Computer programs can be characterized as interactive or batch in terms of what drives them and
how continuously they run.
Interactive programs. These programs receive data from an interactive user or possibly
from another program that simulates an interactive user. A command interpreter or a
web browser are examples of an interactive program.
Batch programs. These programs run, do their work and then stop. A batch program can be
started directly by a user, or it can be invoked to run by an interactive program. A program
that computes and prints out a company payroll is an example of a batch program. Print jobs
are also batch programs.
1. Operating Systems
An operating system is a computer program that provides a standard environment for users and
for running other computer programs. For example, Linux, android, iOS and Windows are
operating systems.
2. Application
An application is any computer program that is written primarily for people to use. This includes
broad categories such as office productivity, business software and media software.
3. Systems
Systems are computer programs that are primarily designed for automation as opposed as acting
as a tool for people to use. For example, a payment system that performs transaction processing
for purchases.
2
4. Platforms
Platforms are environments for building systems and applications for the cloud or a particular
device.
5. Embedded Systems
Embedded systems are computers and computer programs that are placed in everyday devices
such as a vacuum cleaner or bottle of water.
A programming language is mainly used to develop desktop applications, websites, and mobile
applications.
i. Machine Language
Machine language is a type of low-level programming language. It is also called as machine code
or object code. It does not require a translator to convert the programs because computers
directly understand the machine language programs.
The advantage of machine language is that it helps the programmer to execute the programs
faster than the high-level programming language.
3
ii. Assembly Language
Assembly language (ASM) is also a type of low-level programming language that is designed for
specific processors. It represents the set of instructions in a symbolic and human-understandable
form. It uses an assembler to convert the assembly language to machine language.
The advantage of assembly language is that it requires less memory and less execution time to
execute a program.
High-level programming language includes Python, Java, JavaScript, PHP, C#, C++, Objective
C, COBOL, Perl, Pascal, LISP, FORTRAN, and Swift programming language.
Procedural Oriented Programming (POP) language is derived from structured programming and
based upon the procedure call concept. It divides a program into small procedures called routines
or functions.
The advantage of POP language is that it helps programmers to easily track the program flow
and code can be reused in different parts of the program.
4
ii. Object-Oriented Programming language
Object-Oriented Programming (OOP) language is based upon the objects. In this programming
language, programs are divided into small parts called objects. It is used to implement real-world
entities like inheritance, polymorphism, abstraction, etc. in the program to makes the program
reusable, efficient, and easy-to-use.
The main advantage of object-oriented programming is that OOP is faster and easier to execute,
maintain, modify, as well as debug.
Natural language is a part of human languages such as English, Russian, German, and Japanese.
It is used by machines to understand, manipulate, and interpret human's language. It is used by
developers to perform tasks such as translation, automatic summarization, Named Entity
Recognition (NER), relationship extraction, and topic segmentation.
The main advantage of natural language is that it helps users to ask questions in any subject and
directly respond within seconds.
Middle-level programming language lies between the low-level programming language and
high-level programming language. It is also known as the intermediate programming language
and pseudo-language.
A middle-level programming language's advantages are that it supports the features of high-level
programming, it is a user-friendly language, and closely related to machine language and human
language.
5
Most commonly used Programming Language
There are dozens of programming languages used by the industries. Some most widely used
programming languages are given below -
Python is one of the most widely used user-friendly programming languages. It is an open-source
and easy to learn programming language developed in the 1990s. It is mostly used in Machine
learning, Artificial intelligence, Big Data, GUI based desktop applications, and Robotics.
Advantages
Python executes code line-by-line, so it is easy for the programmer to find the error that
occurred in the code.
Python is platform-independent means you can write code once and run it anywhere.
Disadvantages
Python works with the interpreter. That's why it is slower than other programming
languages like C and C++.
6
Advantages
Java is easy to write, compile, learn, and debug as compared to other programming
languages.
Disadvantages
Java consumes more memory and slower than other programming languages like C or
C++.
3. C Programming Language
Advantages
Disadvantages
C++ is one of the thousands of programming languages that we use to develop software. C. It is
similar to the C programming language but also includes some additional features such as
exception handling, object-oriented programming, type checking, etc.
Advantages
It provides high-level abstraction and useful for a low-level programming language, and
more efficient for general-purpose.
Disadvantages
5. C# Programming Language
Advantages
8
C# is a modern, type-safe, easy, fast, and open-source programming language that is
easily integrated with Windows.
C# includes a strong memory backup facility. That's why it avoids the problem of
memory leakage.
Disadvantages
JavaScript is a type of scripting language that is used on both client-side as well as a server-side.
It is developed in the 1990s for the Netscape Navigator web browser. It helps programmers to
create dynamic websites, servers, mobile applications, animated graphics, games, and more.
Advantage
It has the ability to create attractive, dynamic websites, and rich interfaces.
Disadvantage
To prevent incorrect operation of a software or system, debugging is used to find and resolve
bugs or defects.
A bug.
A software bug is an error, flaw or fault in a computer program or system that causes it to
produce an incorrect or unexpected result, or to behave in unintended ways.
Types of bugs.
1. Functional errors
This is a broad type of error that happens whenever software doesn’t behave as intended. For
example, if the end user clicks the “Save” button, but their entered data isn’t saved, this is a
functional error. After some investigation, a software tester may identify a more specific culprit
behind the error and reclassify it as a different type of bug.
2. Syntax errors
A syntax error occurs in the source code of a program and prevents the program from being
properly compiled. This type of error is very common and typically occurs when there are one or
more missing or incorrect characters in the code. For example, a single missing bracket could
cause a syntax error.
Compiling programs typically indicate where a syntax error has occurred so the programmer can
fix it.
3. Logic errors
A logic error represents a mistake in the software flow and causes the software to behave
incorrectly. This type of error can cause the program to produce an incorrect output, or even
hang or crash. Unlike syntax errors, logic errors will not prevent a program from compiling.
A common logic error is the infinite loop. Due to poorly written code, the program repeats a
sequence endlessly until it crashes or halts due to external intervention, such as the user closing a
browser window or turning the power off.
10
4. Calculation errors
Anytime software returns an incorrect value — whether it’s one the end user sees or one that’s
passed to another program — that’s a calculation error. This could happen for several reasons:
While such an error can be costly in certain contexts — like in banking, where an incorrect
calculation can result in the loss of money — hunting down the calculation error is typically just
a matter of math.
5. Unit-level bugs
Unit-level software bugs are the most common. They’re also typically the easiest to fix.
After your software is initially coded, you need to see how it works through unit testing —
taking a small, logical section of code and verifying that it performs as designed. This is where
various forms of state machine bugs, calculation errors, and basic logic bugs are often
uncovered.
This type of bug occurs when two or more pieces of software from separate subsystems interact
erroneously. Often the two sets of code are written by different developers. LaVine explains that
even when there’s a solid set of requirements for developers to follow, there’s usually some level
of interpretation required or details that get overlooked, causing the interaction between two
pieces of software to fail.
“System-level integration bugs are harder to fix because you’re dealing with more than one piece
of software, so the complexity increases while overall visibility decreases,” LaVine says. “This
class of bug is often caused by things like byte-swapping, message parsing, or memory overflow
issues.”
LaVine notes that these types of software bugs show up when the end user interacts with the
software in ways that weren’t expected. This often occurs when the user sets a parameter outside
the limits of intended use, such as entering a significantly larger or smaller number than coded
for or inputting an unexpected data type, like text where a number should be.
11
The debugging process:
1. Reproduce the problem.
2. Describe the bug. Try to get as much input from the user to get the exact reason.
3. Capture the program snapshot when the bug appears. Try to get all the variable values
and states of the program at that time.
4. Analyze the snapshot based on the state and action. Based on that try to find the cause of
the bug.
5. Fix the existing bug, but also check that any new bug does not occur.
Debugging Approaches:
Brute force method: It is the most common method of debugging but is the least efficient
method. In this approach, print statements are inserted throughout the program to print the
intermediate values with the hope that some of the printed values will help to identify the
statement in error. This approach becomes more systematic with the use of a symbolic debugger
is also called a source code debugger.
Backtracking: This is also a fairly common approach. In this approach, starting from the
statement at which an error symptom has been observed, the source code is traced backwards
until the error is discovered. Unfortunately, as the number of source lines to be traced back
increases, the number of potential backward paths increases.
Cause elimination method: In this approach, once a failure is observed, the symptoms of the
failure are noted. Based on the failure symptoms, the causes which could have contributed to the
symptom is developed and tests are conducted to eliminate each. A related technique of
identification of the error from the error symptom is the software fault tree analysis.
4. Program slicing: This technique is similar to backtracking. In the backtracking approach, one
often has to examine a large number of statements. However, the search space is reduced by
defining slices. A slice of a program for a particular variable and at a particular statement is the
set of source lines preceding this statement that can influence the value of that variable. Program
slicing makes use of the fact that an error in the value of a variable can be caused by the
statements on which it is data-dependent.
Debugging Tools
There are two debugging tools. The first is a trace mechanism that can be used on the global
functions in the top-level loop.
12
The second tool is a debugger that is not used in the normal top-level loop. After a first program
run it is possible to go back to breakpoints, and to inspect values or to restart certain functions
with different arguments.
This second tool only runs under UNIX, because it duplicates the running process via a fork
13
PROGRAM TESTING
Testing is the process of executing a program with the aim of finding errors. To make our
software perform well it should be error-free. If testing is done successfully it will remove all the
errors from the software.
Principles of Testing: -
i. All the test should meet the customer requirements
iii. Exhaustive testing is not possible. As we need the optimal amount of testing based on the
risk assessment of the application.
v. It follows the Pareto rule (80/20 rule) which states that 80% of errors come from 20% of
program components.
vi. Start testing with small parts and extend it to large parts.
Types of Testing: -
1. Unit Testing
It focuses on the smallest unit of software design. In this, we test an individual unit or group of
interrelated units. It is often done by the programmer by using sample input and observing its
corresponding outputs.
2. Integration Testing
The objective is to take unit tested components and build a program structure that has been
dictated by design. Integration testing is testing in which a group of components is combined to
produce output.
Integration testing is of four types: (i) Top-down (ii) Bottom-up (iii) Sandwich (iv) Big-Bang
3. Regression Testing
14
Every time a new module is added leads to changes in the program. This type of testing makes
sure that the whole component works properly even after adding components to the complete
program.
4. Smoke Testing
This test is done to make sure that software under testing is ready or stable for further testing
It is called a smoke test as the testing an initial pass is done to check if it did not catch the fire or
smoke in the initial switch on.
5. Alpha Testing
This is a type of validation testing. It is a type of acceptance testing which is done before the
product is released to customers. It is typically done by QA people.
6. Beta Testing
The beta test is conducted at one or more customer sites by the end-user of the software. This
version is released for a limited number of users for testing in a real-time environment
7. System Testing
This software is tested such that it works fine for the different operating systems. It is covered
under the black box testing technique. In this, we just focus on the required input and output
without focusing on internal working.
8. Object-Oriented Testing
This testing is a combination of various testing techniques that help to verify and validate object-
oriented software. This testing is done in the following manner:
i. Testing of Requirements,
15
iv. Integration testing,
v. System testing,
3. Test Complete
4. Ranorex
5. Sahi
6. Watir
9. Katalon Studio
16
https://www.jotform.com/blog/types-of-software-bug/
https://www.techtarget.com/searchsoftwarequality/definition/debugging/
17