Testing and Debugging UCT Department of Computer Science Computer Science 1015F Hussein Suleman March 2009.

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

FIT FIT1002 Computer Programming Unit 19 Testing and Debugging.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts and Debugging.
The IDE (Integrated Development Environment) provides a DEBUGGER for locating and correcting errors in program logic (logic errors not syntax errors) The.
Java Review 2 – Errors, Exceptions, Debugging Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts, Testing and Debugging.
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.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering.
Intro to Java Programming  A computer follows the instruction precisely and exactly.  Anything has to be declared and defined before it can be used.
CSC 1051 M.A. Papalaskari, Villanova University Repetition CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing.
Selection Hussein Suleman UCT Dept of Computer Science CS115 ~ 2004.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Chapter 10 – Testing and Debugging. Chapter Goals ► Learn techniques to test your code ► Learn to carry out unit tests ► Understand principles of test.
Input & Output In Java. Input & Output It is very complicated for a computer to show how information is processed. Although a computer is very good at.
2_Testing Testing techniques. Testing Crucial stage in the software development process. Significant portion of your time on testing for each programming.
1 Debugging. 2 A Lot of Time is Spent Debugging Programs Debugging. Cyclic process of editing, compiling, and fixing errors. n Always a logical explanation.
Chapter 5 Loops.
Problem of the Day  Why are manhole covers round?
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.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
Problem of the Day  Why are manhole covers round?
Copyright © 2012 Pearson Education, Inc. Chapter 6 More Conditionals and Loops Java Software Solutions Foundations of Program Design Seventh Edition John.
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
CSC Programming I Lecture 6 September 4, 2002.
Java Basics Hussein Suleman March 2007 UCT Department of Computer Science Computer Science 1015F.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
1 Debugging and Syntax Errors in C++. 2 Debugging – a process of finding and fixing bugs (errors or mistakes) in a computer program.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
CSC 1051 M.A. Papalaskari, Villanova University Algorithms Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Software Engineering1  Verification: The software should conform to its specification  Validation: The software should do what the user really requires.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
1 CSE1301 Computer Programming: Lecture 16 Flow Diagrams and Debugging.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
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.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
UCT Department of Computer Science Computer Science 1015F Iteration
Software Testing CS II: Data Structures & Abstraction
ME 142 Engineering Computation I
Testing Tutorial 7.
Testing and Debugging PPT By :Dr. R. Mall.
Dept of Computer Science University of Maryland College Park
CS1101X Programming Methodology
Testing and Debugging.
Chapter 6 More Conditionals and Loops
Maha AlSaif Maryam AlQattan
2_Testing Testing techniques.
Types of Testing Visit to more Learning Resources.
SELECTION STATEMENTS (1)
Chapter 15 Debugging.
Outline Boolean Expressions The if Statement Comparing Data
CS110D Programming Language I
Chapter 15 Debugging.
Repetition Statements
CSC 1051 – Data Structures and Algorithms I
CSE 1020:Software Development
Outline Software Development Activities
Lecture 14: Testing Testing used to verify object behavior through designed test suites Can test Classes – “unit” testing Object interactions – “integration”
Outline Boolean Expressions The if Statement Comparing Data
Review of Previous Lesson
CSS161: Fundamentals of Computing
CHAPTER 6 Testing and Debugging.
Repetition CSC 1051 – Data Structures and Algorithms I Course website:
Chapter 15 Debugging.
Presentation transcript:

Testing and Debugging UCT Department of Computer Science Computer Science 1015F Hussein Suleman March 2009

Errors and testing  Quick Poll  In a typical hour spent programming, how many minutes do you spend fixing errors?

Errors  What is an error? When your program does not behave as intended or expected.  What is a bug? “…a bug crept into my program …”  Debugging the art of removing bugs

Types of Errors  Compile-time Error Discovered by Java when you hit “compile”. Improper use of Java language. e.g., int x + 1;  Run-time Error Program compiles but does not execute as expected. e.g., int x=0, y = 15/x;

Types of Errors II  Logic Error Program compiles and runs but produces incorrect results - because of a flaw in the algorithm or implementation of algorithm. int a = Keyboard.readInt(); int b = Keyboard.readInt(); int maximum; if (a < b) { maximum = a; } else { maximum = b; }

Testing Methods  Programs must be thoroughly tested for all possible input/output values to make sure the programs behave correctly.  But how do we test for all values of integers? int a = Keyboard.readInt(); if (a 100) { System.out.println (“Error”); }

Equivalence Classes  Group input values into sets with similar expected behaviour and choose candidate values e.g., -50, 50, 150  Choose values at and on either side of boundaries (boundary value analysis) e.g., 0, 1, 2, 99, 100, 101

Path Testing Path 1: a=35Path 2: a=-5  Create test cases to test every path of execution of the program at least once. int a = Keyboard.readInt(); if (a 100) { System.out.println (“Error”); }

Statement Coverage  What if we had: if (a < 25) { System.out.println (“Error in a”); } else { System.out.println (“No error in a”); } if (b < 25) { System.out.println (“Error in b”); } else { System.out.println (“No error in b”); }  Rather than test all paths, test all statements at least once. e.g., (a,b) = (10, 10), (50, 50)

Glass and Black Boxes  If you can create your test cases based on only the problem specification, this is black box testing.  If you have to look at the code, this is glass box testing.  Which categories do these fall in:  Equivalence classes/boundary values  Path coverage  Statement coverage

Test Cases Example equivalence classes: small multiple of 5: 5 small non-multiples of 5: 3 large multiple of 5: 25 large non-multiples of 5: 23 boundary values: 4, 5, 6, 9, 10, 11, 14, 15, 16 statement coverage: 5, 14 path coverage: 5, 7, 13, 20 // Software Testing sample // hussein suleman // CSC1015F // 19 March 2007 import java.util.Scanner; class SoftwareTesting { public static void main ( String [] args ) { // get a number Scanner scan = new Scanner (System.in); int input = scan.nextInt(); input += 10; // check if it is small or large if (input < 20) System.out.print ("small number"); else System.out.print ("large number"); // check if it is divisible by 5 if (input % 5 == 0) System.out.println (" divisible by 5"); } }

Quick Poll  So, which of these is the best approach to determine test values? 1. Exhaustive testing of all values 2. Equivalence classes and boundary values 3. Path testing 4. Statement coverage

Debugging  Debugging is the process of finding errors or bugs in the code.  A debugger is a tool for executing an application where the programmer can carefully control execution and inspect data.  Features include: step through code one instruction at a time viewing variables insert and remove breakpoints to pause execution

Assertions  In Java a programmer can specify conditions that must always be satisfied at particular points (invariants) or the program produces an error. This is an assertion.  Example: assert (input > 0);

Tracing trace instruction  Insert temporary statements into code to output values during calculation.  Very useful when there is no debugger!  Example: int x = y*y*2; int z = x+5; System.out.println (z); if (z == 13)‏ { … }