Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.

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 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 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.
Java Review 2 – Errors, Exceptions, Debugging Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
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.
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 Aaron Tan.
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. Definition From the dictionary- the means by which the presence, quality, or genuineness of anything is determined; a means of trial. For software.
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.
Objectives Understand the basic concepts and definitions relating to testing, like error, fault, failure, test case, test suite, test harness. Explore.
CMSC 345 Fall 2000 Unit Testing. The testing process.
2_Testing Testing techniques. Testing Crucial stage in the software development process. Significant portion of your time on testing for each programming.
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.
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.
Testing and Debugging Session 9 LBSC 790 / INFM 718B Building the Human-Computer Interface.
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 Ch. 1: Software Development (Read) 5 Phases of Software Life Cycle: Problem Analysis and Specification Design Implementation (Coding) Testing, Execution.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
1 Program Planning and Design Important stages before actual program is written.
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.
Final Review. From ArrayLists to Arrays The ArrayList : used to organize a list of objects –It is a class in the Java API –the ArrayList class uses an.
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.
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.
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,
Testing and Debugging UCT Department of Computer Science Computer Science 1015F Hussein Suleman March 2009.
Types for Programs and Proofs
CS1101X Programming Methodology
Testing and Debugging.
Loop Structures.
Software Design and Development
2_Testing Testing techniques.
Chapter 18 Software Testing Strategies
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.
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.
Lecture 14: Testing Testing used to verify object behavior through designed test suites Can test Classes – “unit” testing Object interactions – “integration”
Review of Previous Lesson
CHAPTER 6 Testing and Debugging.
Chapter 15 Debugging.
Presentation transcript:

Testing

2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here heavily from Aaron Tan’s presentation: e=web&cd=3&ved=0CCsQFjAC&url=http%3A%2F%2Fw ww.comp.nus.edu.sg%2F~cs1101x%2Flect%2Ftesting_ and_debugging.ppt&ei=qf0NVJG9KqGjigL8sIHoDw&usg =AFQjCNHOoLaP7m7- Q6tCgZJ23fyDLOVbyg&bvm=bv ,d.cGE. CS Computer Science II

3 Programming Errors Compilation / Syntax errors  Grammatically incorrect statement  Occur during the parsing of input code Example: missing a semi-colon  Easiest type of errors to fix. Runtime errors  Occur at runtime. Example: File not found  Java’s exception mechanism can catch such errors. Logic / Semantic errors  Program runs but produces incorrect result. Example: Division by zero  Hard to characterize, hence hardest to fix. Programming errors are also known as bugs  Origin: a moth in the Mark I computer. CS Computer Science II

4 Testing and Debugging 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 CS Computer Science II

5 Testing and Debugging 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. CS Computer Science II

6 Testing and Debugging 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. CS Computer Science II

7 Testing and Debugging Manual walkthroughs  Pencil-and-paper.  Tracing the flow of control between classes and objects.  Verbal walkthroughs CS Computer Science II

8 Testing and Debugging 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 CS Computer Science II

9 Testing and Debugging 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 CS Computer Science II

10 Testing and Debugging 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 CS Computer Science II

11 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 CS Computer Science II

12 Testing Thoroughly For example, Richard can’t spot the error in his code. // 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. CS Computer Science II

13 Testing Thoroughly 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! CS Computer Science II

14 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); } CS Computer Science II

15 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. CS Computer Science II

16 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. CS Computer Science II

17 Debugger Using the debugger  Stepping  Breakpoint  Inspecting variables Using Eclipse Debugger  CS Computer Science II