CHAPTER 6 Testing and Debugging.

Slides:



Advertisements
Similar presentations
Programming Types of Testing.
Advertisements

1 CSE1301 Computer Programming: Lecture 15 Flowcharts and Debugging.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts, Testing and Debugging.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding Computer Components and Operations (continued) A program must be free of syntax.
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
BPC.1 Basic Programming Concepts
Fundamentals of Python: From First Programs Through Data Structures
By: Mr. Baha Hanene Chapter 3. Learning Outcomes We will cover the learning outcome 02 in this chapter i.e. Use basic data-types and input / output in.
CCSA 221 Programming in C CHAPTER 2 SOME FUNDAMENTALS 1 ALHANOUF ALAMR.
The University of Texas – Pan American
Fundamentals of Python: First Programs
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
General Programming Introduction to Computing Science and Programming I.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Programming Lifecycle
Designing and Debugging Batch and Interactive COBOL Programs Chapter 5.
CHAPTER 2 PART #3 INPUT - OUTPUT 1 st semester King Saud University College of Applied studies and Community Service Csc
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
The Software Development Process
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
1 Program Planning and Design Important stages before actual program is written.
Lecture 5: Stopping with a Sentinel. Using a Sentinel Problem Develop a class-averaging program that will process an arbitrary number of grades each time.
The Hashemite University Computer Engineering Department
Principles of Programming CSEB134 : BS/ CHAPTER Fundamentals of the C Programming Language.
1 CSE1301 Computer Programming: Lecture 16 Flow Diagrams and Debugging.
© 2006 Pearson Education Chapter 3 Part 2 More about Strings and Conditional Statements Loops (for and while) 1.
ALGORITHMS AND FLOWCHARTS
CS1010 Programming Methodology
Introduction to Computing Science and Programming I
CSC201: Computer Programming
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
1-1 Logic and Syntax A computer program is a solution to a problem.
Chapter 2: Input, Processing, and Output
DDC 1023 – Programming Technique
Chapter 2 Assignment and Interactive Input
ICS103 Programming in C Lecture 3: Introduction to C (2)
The Selection Structure
Lecture 2 Introduction to Programming
Lecture 13 & 14.
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
A First Book of ANSI C Fourth Edition
Chapter 2 part #3 C++ Input / Output
Designing and Debugging Batch and Interactive COBOL Programs
Arrays, For loop While loop Do while loop
An Introduction to Structured Program Design in COBOL
The while Looping Structure
The ‘while’ loop ‘round and ‘round we go.
Chapter 2.1 Repetition.
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Programming Errors Key Revision Points.
Homework Applied for cs240? (If not, keep at it!) 8/10 Done with HW1?
Software Development Process
PROGRAMMING FUNDAMENTALS Lecture # 03. Programming Language A Programming language used to write computer programs. Its mean of communication between.
CHAPTER 4 Iterative Structure.
An Introduction to Debugging
Chapter 2 part #3 C++ Input / Output
Chapter 2: Input, Processing, and Output
More Loops Topics Relational Operators Logical Operators for Loops.
Review of Previous Lesson
The while Looping Structure
Chapter 1 c++ structure C++ Input / Output
WJEC GCSE Computer Science
The while Looping Structure
ICS103: Programming in C 5: Repetition and Loop Statements
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Getting Started With Coding
Presentation transcript:

CHAPTER 6 Testing and Debugging

CONTENTS Testing Debugging Programming Errors Test Data

Testing and Debugging Program is checked for errors (bugs) and tested with sample data to see if the actual results produced by the program match the expected result. Testing and Debugging are done after the pseudocode is translated to the targeted programming language (implementation)

Testing and Debugging TESTING Definition: A process of trying out a program with some sample data before declaring it done. DEBUGGING Definition: A process of detecting the program for errors and fixed these errors. (during compilation and execution)

Testing Unit testing - The program/modules that make up a system should first be tested individually and make sure that each works correctly. When programs/modules are put together to make a system, another testing will be done. This testing is called system testing. When finally the whole system were tested. The system will be implemented and integrated. Then the program will be tested. The test is called integration testing. Once tested adequately, it is ready to be put into production or handover to the user. Before the handover of the program to the user, user acceptance test usually are done according to the specification.

Debugging PROGRAMMING ERRORS There is a possibility of encountering any or all of the 3 types of errors in the program: Syntax Errors Execution / Run-time Errors Logic Errors

SYNTAX ERRORS Errors which are related to the programming language used. They occur when programmer does not follow the rules of that language. First stage of error removal Syntax error is easy to find and eliminate. Statements cannot be translated into source code.

SYNTAX ERRORS e.g. of syntax error in C programming : missing semicolon at the end of statement, misspelled reserved words, incorrect syntax etc. Prevents program compilation/interpretation. Program can only be executed if it is syntax error free To examine the program source code, correct the error and then recompile.

SYNTAX ERRORS Find the Syntax errors in the following C Program No semi-colon at the end of #include Spelling mistake – should be int #include <stdio.h>; main() { integer m1,m2,m3,m4; float ave-mark; printf(“Enter 4 test marks: ”); scanf(“%d %d %d %d”,m1,m2,m3,m4); (m1+m2+m3+m4/4 = ave-mark; printf(“Average marks : %0.2f/n”, ave-mark); } #include <stdio.h>; Variable name must not contain special character main() { integer m1,m2,m3,m4; Getting Integer input - must have an ‘&’ in front of the variable name float ave-mark; printf(“Enter 4 test marks: ”); scanf(“%d %d %d %d”,m1,m2,m3,m4); (m1+m2+m3+m4/4 = ave-mark; printf(“Average marks : %0.2f/n”, ave-mark); } Should be forward Slash \ Incorrect mathematical expression, Incorrect assignment syntax

EXECUTION ERRORS Errors which Occurs when executing/running the program Compiler will display error message e.g. Division by zero in function main Possible cause : Trying to read record that does not exists/eof has been reached Wrong data type being entered Disk drive not ready Result overflow e.g. division with 0 Printer not ready

EXECUTION ERRORS #include <stdio.h> main() { int number, sum=0, count = 0; float averagenum; while (reply = ‘y’) { scanf(“%d”, &number); sum = sum + number; } averagenum = sum/count; printf(“%.2f”, &averagenum); Infinite loop due to no terminating statement Division by 0

LOGICAL ERRORS Errors where wrong output is produced due to incorrect program logic. A program which is syntax error free is not necessarily free of logical errors. These errors do not prevent from program execution cannot be detected by computer Not always easy to detect and requires programmer to examine the source code (logic) to rectify the errors.

LOGICAL ERRORS If by examining the program listing does not solve the problem, alternatively : Get other programmer to criticize the program Compare the output with the expected result, check the formulas and output formats Examine the values of key variable add a temporary lines of code in the program to display the value of variables – dummy statement Use of debugging facilities provided to trace the program

LOGICAL ERRORS E.g. A program is required to accept a few numbers and then calculate the average. The program will produce the wrong result if the sum of the numbers is divided by a number other than the total count of numbers

TEST DATA After the program is syntax error free, test it using selected test data The purpose of test data is to detect logical errors in the program Selecting test data must be done carefully. The nature of test data should be such: Every statement is executed at least once It verifies for error in input Every control/condition in the program is tested It ensures the processing accuracy It follows the original design specification

TEST DATA Categories of test data Normal Data Extreme Data This is the general data the program was designed to handle. Extreme Data This is the data within the upper and lower limit of acceptability It is also known as Boundary testing e.g. numeric – largest and smallest number text – shortest and longest text file – with no records or single record Exceptional Data This is the illegal data which the program was not designed to handle Program should reject the input rather than trying to process it e.g. displaying error messages

Class exercise – Problem specification A payroll program is required by a local company to compute an employee’s pay at time and a half of all hours worked over 40 hours for a week. Each employee record will be having employee number, hours worked and standard hourly rate of pay. The program should also be designed to handle input data that is invalid i.e. if the hours worked entered is less than 0 or more than 80 hours, by prompting a suitable error message.

Task 1 : Write the solution algorithm while reply = ‘y’ read empNum, hours, hourly_rate if hours <= 40 then pay = hours * hourly_rate else pay = (40 * hourly_rate) + (hours – 40) * hourly_rate * 1.5 /* pay at time and a half for all hours worked over 40*/ endif print empNum, pay read reply endwhile while hours < 0 and hours > 80 display “Invalid hour entered. Hour must not be less than 0 or more than 80” read hours endwhile

Next….. Decide on the test data which will adequately test all conditions, by specifying them according to the test data category. The test data will determine the validity, integrity and reliability of the data your system process.

TEST DATA - solution Normal Data – 38 hours, 20 hours Extreme Data – 40 hours, 80 hours Exceptional Data – 81 hours, -5 hours