CS1101: Programming Methodology Aaron Tan.

Slides:



Advertisements
Similar presentations
FIT FIT1002 Computer Programming Unit 19 Testing and Debugging.
Advertisements

Debugging Techniques1. 2 Introduction Bugs How to debug Using of debugger provided by the IDE Exception Handling Techniques.
1 CS2200 Software Development Lecture: Testing and Design A. O’Riordan, 2008 K. Brown,
1 CS2200 Software Development Lecture 27: More Testing A. O’Riordan, 2008 K. Brown,
Program Correctness and Efficiency Chapter 2. Chapter 2: Program Correctness and Efficiency2 Chapter Objectives To understand the differences between.
Well-behaved objects 4.0 Testing. 2 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main concepts to.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts and Debugging.
Well-behaved objects Debugging. 2 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Prevention vs Detection.
Ch. 1: Software Development (Read) 5 Phases of Software Life Cycle: Problem Analysis and Specification Design Implementation (Coding) Testing, Execution.
Well-behaved objects Improving your coding skills 1.0.
Testing and Debugging. Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling (Reminder) Zuul Assignment Two.
Software Testing. “Software and Cathedrals are much the same: First we build them, then we pray!!!” -Sam Redwine, Jr.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts, Testing and Debugging.
1 These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 5/e and are provided with permission by.
Outline Types of errors Component Testing Testing Strategy
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
CS1101: Programming Methodology
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
Testing. What is Testing? Definition: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects.
TESTING.
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.
CMSC 345 Fall 2000 Unit Testing. The testing process.
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.
Oct 15, 2007Sprenkle - CS1111 Objectives Creating your own functions.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
Neil Ghani Software testing. 2 Introduction In a perfect world all programs fully verified testing thus redundant Back in the real.
1 Intro to Java Week 12 (Slides courtesy of Charatan & Kans, chapter 8)
COMP 121 Week 1: Testing and Debugging. Testing Program testing can be used to show the presence of bugs, but never to show their absence! ~ Edsger Dijkstra.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability Objects First with Java - A Practical.
UNIT 13 Separate Compilation.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Week 14 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Software Development Problem Analysis and Specification Design Implementation (Coding) Testing, Execution and Debugging Maintenance.
Design - programming Cmpe 450 Fall Dynamic Analysis Software quality Design carefully from the start Simple and clean Fewer errors Finding errors.
Files & Streams cont... Input File Exceptions  A FileNotFoundException is thrown if the file is not found when an attempt is made to open a file  Each.
Software Engineering 2004 Jyrki Nummenmaa 1 BACKGROUND There is no way to generally test programs exhaustively (that is, going through all execution.
OOPDA Intro 5.0. Topics Website and Syllabus Rowan VPN and H:drive BlueJ application and projects Programming Style (Appendix J) Javadoc (Appendix I)
Testing. Have you contacted your project members lately?
Objects First With Java A Practical Introduction Using BlueJ Well-behaved objects 2.1.
1 COS 260 DAY 15 Tony Gauvin. 2 Agenda Questions? 6 th Mini quiz Today –Chapter 6 Assignment 4 posted –Due Nov 9 Capstone progress reports are due –Brief.
Dynamic Testing.
Testing and Debugging. Testing Fundamentals  Test as you develop Easier to find bugs early rather than later Prototyping helps identify problems early.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability Objects First with Java - A Practical.
Debugging What coders (programmers) do to find the errors (“bugs”) in their own programs “Bugs” – Admiral Grace Hopper, developer of the world’s first.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Bugs CS100 how to prevent them, how to find them and how to terminate them.
1 CSE1301 Computer Programming: Lecture 16 Flow Diagrams and Debugging.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
SOFTWARE TESTING LECTURE 9. OBSERVATIONS ABOUT TESTING “ Testing is the process of executing a program with the intention of finding errors. ” – Myers.
1 ENERGY 211 / CME 211 Lecture 14 October 22, 2008.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability © 2017 Pearson Education, Inc. Hoboken,
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
Objects First with Java
CS1101X Programming Methodology
Testing and Debugging.
Loop Structures.
Chapter 18 Software Testing Strategies
COS 260 DAY 17 Tony Gauvin.
Objects First with Java
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Software Testing Program testing can be used to show the presence of bugs, but never to show their absence. – Edgar Dijkstra.
Chapter 15 Debugging.
COS 260 DAY 16 Tony Gauvin.
Chapter 1: Computer Systems
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.
Review of Previous Lesson
CHAPTER 6 Testing and Debugging.
UNIT-4 BLACKBOX AND WHITEBOX TESTING
Presentation transcript:

CS1101: Programming Methodology Aaron Tan

CS1101X: Testing and Debugging 2 Overview Acknowledgement: Cohoon and Davidson; Barnes and Kolling. Testing and debugging are important activities in software development. Techniques and tools are introduced. Part of the material here comes from chapter 13 of Cohoon and Davidson’s book and chapter 6 of Barnes and Kolling’s book “Objects first with Java”.

CS1101X: Testing and Debugging 3 Programming Errors Compilation errors  Syntax error (example: missing a semi-colon).  Semantic error. (For example, applying modulus % on floating- point value for certain programming languages. In Java,is it fine? Yes!)  Easiest type of errors to fix. Runtime errors  Occur at runtime.  Java’s exception mechanism can catch such errors. Logic errors  Program runs but produces incorrect result.  Hard to characterize, hence hardest to fix. Programming errors are also known as bugs  Origin: a moth in the Mark I computer.

CS1101X: Testing and Debugging 4 Testing and Debugging (1/7) Testing  To determine if a code contains errors. Debugging  To locate the error and fix it. Documentation  To improve maintainability of the code.  Include sensible comments, good coding style and clear logic. Testing Yes Error? Debug

CS1101X: Testing and Debugging 5 Testing and Debugging (2/7) Unit testing  Test of individual parts of an application – a single method, a single class, a group of classes, etc. Positive versus negative testing  Positive testing – testing of functionality that we expect to work.  Negative testing – testing cases we expect to fail, and handle these cases in some controlled way (example: catch handler for exception). Test automation  Regression testing – re-running tests that have previously been passed whenever a change is made to the code.  Write a test rig or a test harness. This and the next slides involve materials not covered yet or to be covered in other modules (such as Software Engineering). You will need to gain relevant experience before you can appreciate them. Hence I will skip them for the moment.

CS1101X: Testing and Debugging 6 Testing and Debugging (3/7) Modularization and interfaces  Problem is broken into sub-problems and each sub-problem is tackled separately – divide-and-conquer.  Such a process is called modularization.  The modules are possibly implemented by different programmers, hence the need for well-defined interfaces.  The signature of a method (its return type, name and parameter list) constitutes the interface. The body of the method (implementation) is hidden – abstraction.  Good documentation (example: comment to describe what the method does) aids in understanding. static double maxmax(double a, double b) Returns the greater of two double values.

CS1101X: Testing and Debugging 7 Testing and Debugging (4/7) Manual walkthroughs  Pencil-and-paper.  Tracing the flow of control between classes and objects.  Verbal walkthroughs

CS1101X: Testing and Debugging 8 Testing and Debugging (5/7) Print statements  Easy to add  Provide information: Which methods have been called The value of parameters The order in which methods have been called The values of local variables and fields at strategic points  Disadvantages Not practical to add print statements in every method Too many print statements lead to information overload Removal of print statements tedious

CS1101X: Testing and Debugging 9 Testing and Debugging (6/7) Debugger  Provides Stepping (step and step-into) Breakpoint Tracking of every object’s state Program testing can be used to show the presence of bugs, but never to show their absence. – Edgar Dijkstra

CS1101X: Testing and Debugging 10 Testing and Debugging (7/7) Tips and techniques  Start off with a working algorithm  Incremental coding/test early  Simplify the problem  Explain the bug to someone else  Fix bugs as you find them  Recognize common bugs (such as using ‘=’ instead of ‘==’, using ‘==’ instead of equals( ), dereferencing null, etc.)  Recompile everything  Test boundaries  Test exceptional conditions  Take a break

CS1101X: Testing and Debugging 11 Turning Debugging Info On/Off public static int sum(int a, int b) { int left = 0; int right = data.length - 1; if (debugging) { System.out.println("sum called with a = " + a + " b = " + b); } int total = a + b; if (debugging) { System.out.println("total = " + total); } return total; } debugging = true; int ans = sum(3,5); Debugging on. debugging = false; int ans = sum(3,5); Debugging off. Add an extra boolean debugging field to the class.

CS1101X: Testing and Debugging 12 Black-box and White-box Testing White-box testing indicates that we can “see” or examine the code as we develop test cases Black-box testing indicates that we cannot examine the code as we devise test cases  Seeing the code can bias the test cases we create  Forces testers to use specification rather than the code Complementary techniques

CS1101X: Testing and Debugging 13 Testing Thoroughly (1/2) Recall our discussion last week. Richard couldn’t spot the error in this code of his. // To find the maximum among 3 integer // values in variables num1, num2, num3. int max = 0; if (num1 > num2 && num1 > num3) max = num1; if (num2 > num1 && num2 > num3) max = num2; if (num3 > num1 && num3 > num2) max = num3; He tested it on many sets of data:,,, etc. and the program works for all these data. But he didn’t test it with duplicate values! Eg:,, etc.

CS1101X: Testing and Debugging 14 Testing Thoroughly (2/2) Richard wrote another program. // To find the maximum among 3 integer // values in variables num1, num2, num3. int max = 0; if (num1 > max) max = num1; if (num2 > max) max = num2; if (num3 > max) max = num3; He was told that the program doesn’t work but again he couldn’t figure out why. He has tested it on many data sets, including duplicate values! Can you tell him what he missed out in his testing? Don’t forget the special cases!

CS1101X: Testing and Debugging 15 Testing Boundaries It is important to test the boundary conditions. Input YearInput Month final int CALENDAR_START = 1583; // validate input if ((year 12)) { System.output.println("Bad request: " + year + " " + month); }

CS1101X: Testing and Debugging 16 Path Testing Paths: different routes that your program can take  Design test data to check all paths  Example if (x != 3) { y = 5; } else { z = z - x; } if (z > 1) { z = z / x; } else { z = 0; } if (x != 3) y = 5z = z - x if (z > 1) z = z / x z = 0 A B C D E F G H Paths A, B, G, H. Paths E, F, C, D.

CS1101X: Testing and Debugging 17 Integration and System Testing Integration testing is done as modules or components are assembled.  Attempts to ensure that pieces work together correctly  Test interfaces between modules System testing occurs when the whole system is put together This comes in when you start to write bigger programs.

CS1101X: Testing and Debugging 18 Debugger Using the debugger  Stepping  Breakpoint  Inspecting variables I will illustrate on DrJava

CS1101X: Testing and Debugging 19 Other readings Some websites  html html  AndTesting.htm AndTesting.htm

CS1101X: Testing and Debugging 20 End of File