Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.

Slides:



Advertisements
Similar presentations
Advanced Programming 15 Feb The “OI” Programming Process Reading the problem statement Thinking Coding + Compiling Testing + Debugging Finalizing.
Advertisements

COMPUTER PROGRAMMING I Essential Standard 5.02 Understand Breakpoint, Watch Window, and Try And Catch to Find Errors.
Chapter 3: Editing and Debugging SAS Programs. Some useful tips of using Program Editor Add line number: In the Command Box, type num, enter. Save SAS.
FIT FIT1002 Computer Programming Unit 19 Testing and Debugging.
Debugging Techniques1. 2 Introduction Bugs How to debug Using of debugger provided by the IDE Exception Handling Techniques.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts and Debugging.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
Loops Repeat after me …. Loops A loop is a control structure in which a statement or set of statements execute repeatedly How many times the statements.
16/27/2015 3:38 AM6/27/2015 3:38 AM6/27/2015 3:38 AMTesting and Debugging Testing The process of verifying the software performs to the specifications.
Exceptions Objectives At the conclusion of this lesson, students should be able to Explain the need for exceptions Correctly write programs that use.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts, Testing and Debugging.
DEBUGGERS For CS302 Data Structures Course Slides prepared by TALHA OZ (most of the text is from
Debugging Logic Errors CPS120 Introduction to Computer Science Lecture 6.
28/08/2015SJF L31 F21SF Software Engineering Foundations ASSUMPTIONS AND TESTING Monica Farrow EM G30 Material available on Vision.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
REPETITION STRUCTURES. Topics Introduction to Repetition Structures The while Loop: a Condition- Controlled Loop The for Loop: a Count-Controlled Loop.
Fruitful functions. Return values The built-in functions we have used, such as abs, pow, int, max, and range, have produced results. Calling each of these.
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.
CONTROL FLOW IN C++ Satish Mishra PGT CS KV Trimulgherry.
Programming Translators.
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
1 Principles of Computer Science I Prof. Nadeem Abdul Hamid CSC 120 – Fall 2005 Lecture Unit 10 - Testing.
Chapter 10 – Testing and Debugging. Chapter Goals ► Learn techniques to test your code ► Learn to carry out unit tests ► Understand principles of test.
Debugging in Java. Common Bugs Compilation or syntactical errors are the first that you will encounter and the easiest to debug They are usually the result.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
Unit Testing 101 Black Box v. White Box. Definition of V&V Verification - is the product correct Validation - is it the correct product.
Program Errors and Debugging Week 10, Thursday Lab.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
CS101 Computer Programming I Chapter 4 Extra Examples.
CS Class 05 Topics  Selection: switch statement Announcements  Read pages 74-83, ,
The Software Development Process
Java Basics Hussein Suleman March 2007 UCT Department of Computer Science Computer Science 1015F.
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
Week 14 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Introduction to Loops Iteration Repetition Counting Loops Also known as.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Repetition Structures.
CSC 1010 Programming for All Lecture 4 Loops Some material based on material from Marty Stepp, Instructor, University of Washington.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
Outline Announcements: –HW I key online this afternoon –HW II due Friday –Sign up to discuss projects Debugging Testging for correctness.
AVCE ICT – Unit 7 - Programming Session 12 - Debugging.
CS1010: Programming Methodology
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
1 CSE1301 Computer Programming: Lecture 16 Flow Diagrams and Debugging.
Debugging and Testing Hussein Suleman March 2007 UCT Department of Computer Science Computer Science 1015F.
Debuggers. Errors in Computer Code Errors in computer programs are commonly known as bugs. Three types of errors in computer programs –Syntax errors –Runtime.
Discussion 4 eecs 183 Hannah Westra.
Component 1.6.
Handouts Software Testing and Quality Assurance Theory and Practice Chapter 4 Control Flow Testing
CS1101X Programming Methodology
Testing and Debugging.
Chapter 2 Assignment and Interactive Input
Computer Programming I
Testing Key Revision Points.
Topics Introduction to Repetition Structures
CSS 161: Fundamentals of Computing
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Chapter 15 Debugging.
Algorithm Correctness
Chapter 15 Debugging.
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
CISC101 Reminders Assignment 3 due next Friday. Winter 2019
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
CSE 1020:Software Development
Review of Previous Lesson
Chapter 15 Debugging.
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Chapter 15 Debugging.
Presentation transcript:

Testing and Debugging Version 1.0

All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code Your program runs, but produces the wrong answers Your program crashes unexpectedly

Learning to interpret compiler messages and spot syntax errors in your code comes with lots of experience. There is no magic bullet here.

But what do you after your program compiles. How do you know that it runs correctly? How do you isolate and fix problems? That’s where testing and debugging come in.

Unit Testing Unit testing is a powerful tool programmers use to test individual methods, or simple programs, to make sure that they are working correctly.

Unit Testing When unit testing a method, compile the method outside of the program it will be used in, along with a test harness that will feed the method a series of test values. Test values may come as user input, from a loop, or from a random number generator.

Suppose, for example, that you have written a method that calculates e x using the series e x = x / 1 + x 2 / 2 + x 3 / 6 + x 4 / 24 + x 5 / …

Write the method (for integer values of x) // The Etox method static double Etox(int x) { double divisor = 1.0; double newex = 1.0; double ex = 0.0; double EPSILON = ; int p = 1; do { ex = newex; divisor = divisor * p; newex = ex + Math.Pow(x, p) / divisor; p++; } while (Math.Abs(newex - ex) > EPSILON); return ex; }//End Etox() This method uses a loop that keeps adding terms to the series until the change in the result is smaller than

Now write a test harness. This code is simply a driver that repeatedly tests the method with different values. In this case the input comes from the user.

The Test Harness static void Main() { int inputValue = 0; Console.WriteLine("Test Harness for e to the x method"); do { Console.Write("Input a test value... 0 to quit: "); inputValue = int.Parse(Console.ReadLine()); double ex = etox(inputValue); Console.WriteLine("For a value of x = {0} e to the x = {1}", inputValue, ex); } while (inputValue != 0); }//End Main() This methodcalls the Etox method and prints the results, which you can verify manually.

How do you know what values to use when testing the method?

You should test with Typical values that a user might call the method with Boundary values Invalid values that you know should fail

As a method of the real variable x, the graph of y=e x is always positive (above the x axis) and increasing (viewed left-to-right). It never touches the x axis, although it gets arbitrarily close to it.

Some interesting test cases might be when x = 0, and when x is a large negative number.

As x gets very very large or very very small, we can expect this method to overflow, i.e. a double won’t be big enough to hold the answer.

This kind of testing is known as Black-Box testing, since there is no consideration of the internal workings of the method. We only give it some fixed set of inputs and see if the method produces the correct outputs.

Testing that looks at what is happening inside of a method as it executes is called White Box testing. In white box testing you should be sure that your test cases exercise every code path in the method.

Many branches in a program are provided to handle bad input values (for example, an invalid file name). Be sure that You test these branches too. Your program should do the correct thing in the presence of bad input.

How do you know if your outputs are correct or not? You can calculate them by hand You can look them up in a table You can do a “reverse” calculation You can use another, perhaps less efficient means of calculating the result

Debugging When testing reveals problems in your code, you have to find out why your code doesn’t work correctly and fix it. This process is called debugging.

The basic steps required to debug code are: 1.Recognize that an error (bug) exists in the code 2.Isolate the error – where is it in the code 3.Identify the source of the bug – what causes it 4.Figure out how to fix the code 5.Apply the fix and re-test the code.

Where’s the bug?

Before you can successfully locate a bug in Your code you have to know what it is that your program is supposed to be doing. Why is each branch taken? How many times should a loop be executed? What values do you expect in your variables at each step of the program?...

Things you can do to understand the flow of control * Draw an activity diagram * Desk check your code

Program Traces If you are not sure what paths are being taken in a program, or how values may change as the program is executed, you can insert trace messages at key points within the program. You can print out values of parameters or other important data elements at these points. Each time a method is entered Each time a method returns Each time a loop is entered Each time a branch is taken

Program Traces Using program traces can be time consuming, and … you have to be careful to take all trace statements out of your program when you are done … but it can be a very effective tool.

Using a Debugger Most modern software development environments include a built in debugger. Debuggers allow you to Create breakpoints (stopping points in your code) Step through your code a line at a time (single step) Inspect variables (watch windows)

The lab assignment this week introduces you to the debugger that is built in to Visual C# Express Edition.