Regression testing Whenever you find a bug – Reproduce it (before you fix it!) – Store input that elicited that bug – Store correct output – Put into test.

Slides:



Advertisements
Similar presentations
Test-First Programming. The tests should drive you to write the code, the reason you write code is to get a test to succeed, and you should only write.
Advertisements

CSE 331 SOFTWARE DESIGN & IMPLEMENTATION DEBUGGING Autumn 2011 Bug-Date: Sept 9, 1947.
Annoucements  Next labs 9 and 10 are paired for everyone. So don’t miss the lab.  There is a review session for the quiz on Monday, November 4, at 8:00.
An Introduction to Java Programming and Object- Oriented Application Development Chapter 8 Exceptions and Assertions.
Error Management with Design Contracts Karlstad University Computer Science Error Management with Design Contracts Eivind J. Nordby, Martin Blom, Anna.
API Design CPSC 315 – Programming Studio Fall 2008 Follows Kernighan and Pike, The Practice of Programming and Joshua Bloch’s Library-Centric Software.
Software Engineering and Design Principles Chapter 1.
Nov 10, Fall 2006IAT 8001 Debugging. Nov 10, Fall 2006IAT 8002 How do I know my program is broken?  Compiler Errors –easy to fix!  Runtime Exceptions.
Debugging CPSC 315 – Programming Studio Fall 2008.
1 Sharing Objects – Ch. 3 Visibility What is the source of the issue? Volatile Dekker’s algorithm Publication and Escape Thread Confinement Immutability.
Test-Driven Development “Test first, develop later!” –OCUnit.
1 Functional Testing Motivation Example Basic Methods Timing: 30 minutes.
Computer Science 340 Software Design & Testing Design By Contract.
CS527: (Advanced) Topics in Software Engineering Overview of Software Quality Assurance Tao Xie ©D. Marinov, T. Xie.
Dr. Pedro Mejia Alvarez Software Testing Slide 1 Software Testing: Building Test Cases.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
P51UST: Unix and Software Tools Unix and Software Tools (P51UST) Compilers, Interpreters and Debuggers Ruibin Bai (Room AB326) Division of Computer Science.
CSE 486/586 CSE 486/586 Distributed Systems PA Best Practices Steve Ko Computer Sciences and Engineering University at Buffalo.
Software Quality Assurance Lecture #8 By: Faraz Ahmed.
University of Palestine software engineering department Testing of Software Systems Fundamentals of testing instructor: Tasneem Darwish.
Jun 16, 2014IAT 2651 Debugging. Dialectical Materialism  Dialectical materialism is a strand of Marxism, synthesizing Hegel's dialectics, which proposes.
1 Debugging and Testing Overview Defensive Programming The goal is to prevent failures Debugging The goal is to find cause of failures and fix it Testing.
Testing Michael Ernst CSE 140 University of Washington.
Testing CSE 140 University of Washington 1. Testing Programming to analyze data is powerful It’s useless if the results are not correct Correctness is.
Introduction to Testing 1. Testing  testing code is a vital part of the development process  the goal of testing is to find defects in your code  Program.
CSE 219 Computer Science III Testing. Testing vs. Debugging Testing: Create and use scenarios which reveal incorrect behaviors –Design of test cases:
Debugging CSE 331 University of Washington 1. Ways to get your code right Validation Purpose is to uncover problems and increase confidence Combination.
Low-Level Detailed Design SAD (Soft Arch Design) Mid-level Detailed Design Low-Level Detailed Design Design Finalization Design Document.
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?
Introduction to Software Testing. Types of Software Testing Unit Testing Strategies – Equivalence Class Testing – Boundary Value Testing – Output Testing.
DEBUGGING. BUG A software bug is an error, flaw, failure, or fault in a computer program or system that causes it to produce an incorrect or unexpected.
Exceptions and assertions CSE 331 University of Washington.
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.
(1) Unit Testing and Test Planning CS2110: SW Development Methods These slides design for use in lab. They supplement more complete slides used in lecture.
Reasoning about programs March CSE 403, Winter 2011, Brun.
What is Testing? Testing is the process of finding errors in the system implementation. –The intent of testing is to find problems with the system.
Design - programming Cmpe 450 Fall Dynamic Analysis Software quality Design carefully from the start Simple and clean Fewer errors Finding errors.
Scientific Debugging. Errors in Software Errors are unexpected behaviors or outputs in programs As long as software is developed by humans, it will contain.
CSE 332: C++ Statements C++ Statements In C++ statements are basic units of execution –Each ends with ; (can use expressions to compute values) –Statements.
Objects First With Java A Practical Introduction Using BlueJ Well-behaved objects 2.1.
Testing CSE 160 University of Washington 1. Testing Programming to analyze data is powerful It’s useless (or worse!) if the results are not correct Correctness.
CSE 331 Software Design & Implementation Dan Grossman Fall 2014 Debugging (Based on slides by Mike Ernst, David Notkin, Hal Perkins)
SWE 4743 Abstract Data Types Richard Gesick. SWE Abstract Data Types Object-oriented design is based on the theory of abstract data types Domain.
Software Quality Assurance and Testing Fazal Rehman Shamil.
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
Programming & Debugging. Key Programming Issues Modularity Modifiability Ease of Use Fail-safe programming Style Debugging.
Zach Tatlock / Winter 2016 CSE 331 Software Design and Implementation Lecture 15 Debugging.
Week 6 MondayTuesdayWednesdayThursdayFriday Testing III Reading due Group meetings Testing IVSection ZFR due ZFR demos Progress report due Readings out.
Testing Overview Software Reliability Techniques Testing Concepts CEN 4010 Class 24 – 11/17.
Testing (final thoughts). equals() and hashCode() Important when using Hash-based containers class Duration { public final int min; public final int sec;
Cs498dm Software Testing Darko Marinov January 24, 2012.
CSE 332: C++ Exceptions Motivation for C++ Exceptions Void Number:: operator/= (const double denom) { if (denom == 0.0) { // what to do here? } m_value.
Testing Tutorial 7.
CSE 331 Software Design & Implementation
Chapter 8 – Software Testing
Testing UW CSE 160 Winter 2017.
Testing UW CSE 160 Spring 2018.
CSE 331 Software Design and Implementation
CSE 331 Software Design and Implementation
Testing UW CSE 160 Winter 2016.
CSCE 315 – Programming Studio, Fall 2017 Tanzir Ahmed
CS 1111 Introduction to Programming Fall 2018
CSE 331 Software Design & Implementation
An Introduction to Debugging
Assertions References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 4/25/2019.
Computer Science 340 Software Design & Testing
Presentation transcript:

Regression testing Whenever you find a bug – Reproduce it (before you fix it!) – Store input that elicited that bug – Store correct output – Put into test suite – Then, fix it and verify the fix Why is this a good idea? – Helps to populate test suite with good tests – Protects against regressions that reintroduce bug It happened once, so it might again

Rules of Testing First rule of testing: Do it early and do it often Best to catch bugs soon, before they have a chance to hide. Automate the process if you can Regression testing will save time. Second rule of testing: Be systematic If you randomly thrash, bugs will hide in the corner until you're gone Writing tests is a good way to understand the spec Think about revealing domains and boundary cases If the spec is confusing  write more tests Spec can be buggy too Incorrect, incomplete, ambiguous, and missing corner cases When you find a bug  fix it first and then write a test for it

Testing summary Testing matters – You need to convince others that module works Catch problems earlier – Bugs become obscure beyond the unit they occur in Don't confuse volume with quality of test data – Can lose relevant cases in mass of irrelevant ones – Look for revealing subdomains (“characteristic tests”) Choose test data to cover – Specification (black box testing) – Code (glass box testing) Testing can't generally prove absence of bugs – But it can increase quality and confidence

Debugging February CSE 403, Winter 2011, Brun

Ways to get your code right Validation – Purpose is to uncover problems and increase confidence – Combination of reasoning and test Debugging – Finding out why a program is not functioning as intended Defensive programming – Programming with validation and debugging in mind Testing ≠ debugging – test:reveals existence of problem – debug:pinpoint location + cause of problem

A bug – September 9, 1947 US Navy Admiral Grace Murray Hopper, working on Mark I at Harvard

A Bug’s Life Defect – mistake committed by a human Error – incorrect computation Failure – visible error: program violates its specification Debugging starts when a failure is observed – Unit testing – Integration testing – In the field

Defense in depth 1.Make errors impossible – Java makes memory overwrite bugs impossible 2.Don’t introduce defects – Correctness: get things right the first time 3.Make errors immediately visible – Local visibility of errors: best to fail immediately – Example: checkRep() routine to check representation invariants 4.Last resort is debugging – Needed when effect of bug is distant from cause – Design experiments to gain information about bug Fairly easy in a program with good modularity, representation hiding, specs, unit tests etc. Much harder and more painstaking with a poor design, e.g., with rampant rep exposure

First defense: Impossible by design In the language – Java makes memory overwrite bugs impossible In the protocols/libraries/modules – TCP/IP will guarantee that data is not reordered – BigInteger will guarantee that there will be no overflow In self-imposed conventions – Hierarchical locking makes deadlock bugs impossible – Banning the use of recursion will make infinite recursion/insufficient stack bugs go away – Immutable data structures will guarantee behavioral equality – Caution: You must maintain the discipline

Second defense: correctness Get things right the first time – Don’t code before you think! Think before you code. – If you're making lots of easy-to-find bugs, you're also making hard-to- find bugs – don't use compiler as crutch Especially true, when debugging is going to be hard – Concurrency – Difficult test and instrument environments – Program must meet timing deadlines Simplicity is key – Modularity Divide program into chunks that are easy to understand Use abstract data types with well-defined interfaces Use defensive programming; avoid rep exposure – Specification Write specs for all modules, so that an explicit, well-defined contract exists between each module and its clients

Third defense: immediate visibility If we can't prevent bugs, we can try to localize them to a small part of the program – Assertions: catch bugs early, before failure has a chance to contaminate (and be obscured by) further computation – Unit testing: when you test a module in isolation, you can be confident that any bug you find is in that unit (unless it's in the test driver) – Regression testing: run tests as often as possible when changing code. If there is a failure, chances are there's a mistake in the code you just changed When localized to a single method or small module, bugs can be found simply by studying the program text

Benefits of immediate visibility Key difficulty of debugging is to find the code fragment responsible for an observed problem – A method may return an erroneous result, but be itself error free, if there is prior corruption of representation The earlier a problem is observed, the easier it is to fix – For example, frequently checking the rep invariant helps the above problem General approach: fail-fast – Check invariants, don't just assume them – Don't try to recover from bugs – this just obscures them

How to debug a compiler Multiple passes – Each operate on a complex IR – Lot of information passing – Very complex Rep Invariant – Code generation at the end Bug types: – Compiler crashes – Generated program is buggy Program Front End Intermediate Representation Optimization Intermediate Representation Optimization Intermediate Representation Code Generation Executable RUN 

Don't hide bugs // k is guaranteed to be present in a int i = 0; while (true) { if (a[i]==k) break; i++; } This code fragment searches an array a for a value k. – Value is guaranteed to be in the array. – If that guarantee is broken (by a bug), the code throws an exception and dies. Temptation: make code more “robust” by not failing

Don't hide bugs // k is guaranteed to be present in a int i = 0; while (i<a.length) { if (a[i]==k) break; i++; } Now at least the loop will always terminate – But no longer guaranteed that a[i]==k – If rest of code relies on this, then problems arise later – All we've done is obscure the link between the bug's origin and the eventual erroneous behavior it causes.

Don't hide bugs // k is guaranteed to be present in a int i = 0; while (i<a.length) { if (a[i]==k) break; i++; } assert (i<a.length) : "key not found"; Assertions let us document and check invariants Abort program as soon as problem is detected

Inserting Checks Insert checks galore with an intelligent checking strategy – Precondition checks – Consistency checks – Bug-specific checks Goal: stop the program as close to bug as possible Use debugger to see where you are, explore program a bit

Checking For Preconditions // k is guaranteed to be present in a int i = 0; while (i<a.length) { if (a[i]==k) break; i++; } assert (i<a.length) : "key not found"; Precondition violated? Get an assertion!

Downside of Assertions static int sum(Integer a[], List index) { int s = 0; for (e:index) { assert(e < a.length, “Precondition violated”); s = s + a[e]; } return s; } Assertion not checked until we use the data Fault occurs when bad index inserted into list May be a long distance between fault activation and error detection

checkRep: Data Structure Consistency Checks static void checkRep(Integer a[], List index) { for (e:index) { assert(e < a.length, “Inconsistent Data Structure”); } Perform check after all updates to minimize distance between bug occurrence and bug detection Can also write a single procedure to check ALL data structures, then scatter calls to this procedure throughout code

Bug-Specific Checks static void check(Integer a[], List index) { for (e:index) { assert(e != 1234, “Inconsistent Data Structure”); } Bug shows up as 1234 in list Check for that specific condition

Checks In Production Code Should you include assertions and checks in production code? – Yes: stop program if check fails – don’t want to take chance program will do something wrong – No: may need program to keep going, maybe bug does not have such bad consequences – Correct answer depends on context! Ariane 5 – program halted because of overflow in unused value, exception thrown but not handled until top level, rocket crashes…

Midterm Statistics Mean: 77 StDev: 8.0 Max: 90 Min: 57