Presentation is loading. Please wait.

Presentation is loading. Please wait.

CHAPTER 6 Testing and Debugging.

Similar presentations


Presentation on theme: "CHAPTER 6 Testing and Debugging."— Presentation transcript:

1 CHAPTER 6 Testing and Debugging

2 CONTENTS Testing Debugging Programming Errors Test Data

3 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)

4 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)

5 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.

6 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

7 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.

8 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.

9 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

10 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

11 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

12 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.

13 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

14 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

15 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

16 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

17 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.

18 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

19 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.

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


Download ppt "CHAPTER 6 Testing and Debugging."

Similar presentations


Ads by Google