Software Engineering Testing and Debugging Testing

Similar documents
Software Engineering

Softwaretechnik. Lecture 08: Testing and Debugging Overview. Peter Thiemann SS University of Freiburg, Germany

Softwaretechnik. Lecture 08: Testing and Debugging Overview. Peter Thiemann SS University of Freiburg, Germany

Assertions. Assertions - Example

Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore

Lecture 15 Software Testing

Regression testing. Whenever you find a bug. Why is this a good idea?

Programming Embedded Systems

Chapter 8 Software Testing. Chapter 8 Software testing

Unit Testing as Hypothesis Testing

CSE 331 Final Exam 3/16/15 Sample Solution

References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 10/14/2004 1

Topics in Software Testing

Testing is a very big and important topic when it comes to software development. Testing has a number of aspects that need to be considered.

Unit Testing as Hypothesis Testing

CS 161 Computer Security

Write for your audience

Testing, Debugging, Program Verification

Steps for project success. git status. Milestones. Deliverables. Homework 1 submitted Homework 2 will be posted October 26.

CSE 331 Software Design and Implementation. Lecture 3 Loop Reasoning

Classes, interfaces, & documentation. Review of basic building blocks

Testing, Debugging, and Verification

So, You Want to Test Your Compiler?

CSE 15L Midterm Summer 2011

CITS5501 Software Testing and Quality Assurance Formal methods

From designing to coding

MSO Lecture Design by Contract"

Verification and Validation. Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 22 Slide 1

Quality Assurance in Software Development

Testing. UW CSE 160 Winter 2016

CS 520 Theory and Practice of Software Engineering Fall 2018

Object Oriented Software Design - I

Memory Safety (cont d) Software Security

17. Assertions. Outline. Built-in tests. Built-in tests 3/29/11. Jelle Slowack, Bart Smets, Glenn Van Loon, Tom Verheyen

Software Testing. Software Testing. in the textbook. Chapter 8. Verification and Validation. Verification and Validation: Goals

17. Assertions. Jelle Slowack, Bart Smets, Glenn Van Loon, Tom Verheyen

Lecture 4: Procedure Specifications

No Source Code. EEC 521: Software Engineering. Specification-Based Testing. Advantages

Testing. CMSC 433 Programming Language Technologies and Paradigms Spring A Real Testing Example. Example (Black Box)?

Testing. Topics. Types of Testing. Types of Testing

High Quality Java Code: Contracts & Assertions

LINEAR INSERTION SORT

A Practical Approach to Programming With Assertions

Black Box Testing. EEC 521: Software Engineering. Specification-Based Testing. No Source Code. Software Testing

Outline. Introduction. 2 Proof of Correctness. 3 Final Notes. Precondition P 1 : Inputs include

Computer Science and Software Engineering University of Wisconsin - Platteville 9-Software Testing, Verification and Validation

a correct statement? You need to know what the statement is supposed to do.

Chapter 1: Programming Principles

Static program checking and verification

Program Correctness and Efficiency. Chapter 2

Software Engineering Concepts: Invariants Silently Written & Called Functions Simple Class Example

Software Engineering Testing and Debugging Debugging

Today s Topic. Software Engineering Testing and Debugging Debugging. Today s Topic. The Main Steps in Systematic Debugging

Verification and Validation

Chapter 8 Software Testing. Chapter 8 So-ware tes0ng

Verification and Validation. Assuring that a software system meets a user s needs. Verification vs Validation. The V & V Process

Thread Safety. Review. Today o Confinement o Threadsafe datatypes Required reading. Concurrency Wrapper Collections

Reliable programming

CSE 403: Software Engineering, Fall courses.cs.washington.edu/courses/cse403/16au/ Unit Testing. Emina Torlak

Chapter 1: Principles of Programming and Software Engineering

Static Analysis in Practice

Software Design Models, Tools & Processes. Lecture 6: Transition Phase Cecilia Mascolo

Software Engineering (CSC 4350/6350) Rao Casturi

CSE 331 Summer 2016 Final Exam. Please wait to turn the page until everyone is told to begin.

Comparing procedure specifications

Storing Data in Objects

Agile Manifesto & XP. Topics. Rapid software development. Agile methods. Chapter ) What is Agile trying to do?

Code Contracts in C#

Bridge Course On Software Testing

Announcements. Specifications. Outline. Specifications. HW1 is due Thursday at 1:59:59 pm

hwu-logo.png 1 class Rational { 2 int numerator ; int denominator ; 4 public Rational ( int numerator, int denominator ) {

Principles of Software Construction: Objects, Design, and Concurrency (Part 2: Designing (Sub )Systems)

DEBUGGING: OBSERVING AND TRACKING

Lecture 11: In-Place Sorting and Loop Invariants 10:00 AM, Feb 16, 2018

CPS122 Lecture: Detailed Design and Implementation

DESIGN AND ANALYSIS OF ALGORITHMS. Unit 1 Chapter 4 ITERATIVE ALGORITHM DESIGN ISSUES

"Secure" Coding Practices Nicholas Weaver

Formale Entwicklung objektorientierter Software

Software Engineering

CSE 331 Midterm Exam Sample Solution 2/18/15

CS/ENGRD 2110 FALL Lecture 2: Objects and classes in Java

Relational inductive biases, deep learning, and graph networks

CS 307: Software Engineering. Lecture 10: Software Design and Architecture

Alan J. Perlis - Epigrams on Programming

Software Testing Lecture 1. Justin Pearson

Unit 1 Chapter 4 ITERATIVE ALGORITHM DESIGN ISSUES

Readability [Skrien 4.0] Programs must be written for people to read, and only incidentally for machines to execute.

Software Engineering I (02161)

Testing! The material for this lecture is drawn, in part, from! The Practice of Programming (Kernighan & Pike) Chapter 6!

Testing Objectives. Successful testing: discovers previously unknown errors

Code Documentation.

Software Engineering

Controls Structure for Repetition

Test Driven Development (TDD)

CSE 331 Final Exam 12/14/15 Sample Solution. Question 1. (20 points, 1 each) Warmup. For each statement, circle T if it is true and F if it is false.

Software Engineering

Documentation Nick Parlante, 1996.Free for non-commerical use.

Assertions & Design-by-Contract using JML Erik Poll University of Nijmegen

Software Excellence via Program Analysis at Microsoft. Manuvir Das

Software Engineering and Scientific Computing

Transcription:

Software Engineering Testing and Debugging Testing Prof. Dr. Peter Thiemann Universitt Freiburg 08.06.2011

Recap Testing detect the presence of bugs by observing failures Debugging find the bug causing a certain failure In order to know when a program fails we must have a specification (except for obvious failure such as a program crash) A great deal of care is needed when writing specifications Finding a good set of test cases is often difficult Even with good test cases, absence of failures does not imply absence of bugs (the number of ways to use the program is huge or infinite) Program Verification is about making sure there are no bugs This seems preferable, but software verification is in most cases economically impossible On the other hand, testing is not just a way of finding bugs during the development Making testing a part of the development makes claims about the software more credible

Contents of Testing part Specifications (informal) Test Cases How to write a test case How to come up with a good test suite (collection of test cases)

Specifications Program specifications tell what a piece of code should do But also what it requires to be able to do its job A specification can be seen as contract between the implementor and the user of the implemented code. A specification consists of two parts: Requires (precondition) what the user should fulfill before calling the code Ensures (postcondition) what the implementor promises about the result of the execution (provided requires were fulfilled)

Specification Example 1 public static int find_ min ( int [] a) { 2 int x, i; 3 x = a [0]; 4 for (i = 1; i < a. length ;i ++) { 5 if (a[i] < x) x = a[i]; 6 } 7 return x; 8 } Specification Requires: a is non-null and contains at least one element Ensures: Result is less than or equal to all elements in a and equal to at least one element in a

What can be wrong about a specification? Badly stated does not make sense Vague unclear what is meant Imprecise more can be said about the behaviour Postcondition is too weak Precondition is too strong Incorrect too much is said Precondition is too weak Postcondition is too strong Specification Requires: a is non-null and contains at least one element Ensures: Result is less than or equal to all elements in a and equal to at least one element in a, and result is greater than 0

What can go wrong when writing specifications? Are all these cases of bad specifications? It s clear that we don t want invalid or incorrect specifications. Vague specifications is a matter of whether they can be misunderstood. But imprecise specifications is not such a bad thing

Example: Strong or Weak Precondition Example What does this method do? 1 public static int [] insert ( int [] x, int n) 2 { 3 int [] y = new int [x. length + 1]; 4 int i; 5 for (i = 0; i < x. length ; i ++) { 6 if (n >= x[i]) break ; 7 y[i] = x[i]; 8 } 9 y[i] = n; 10 for (; i < x. length ; i ++) { 11 y[i +1] = x[i]; 12 } 13 return y; 14 }

Example, cont d Example What does this method do? 1 public static int [] insert ( int [] x, int n) 2 {... } Specification Requires: x is non-null and sorted in ascending order. Ensures: Result is equal to x with n inserted in it and result is sorted in ascending order.

Specification of a Class Class invariant A class invariant is a condition about the state of each class instance that should be maintained throughout its existence We will focus on weak invariants It should hold between calls to methods of the class, but not during the execution of such methods Class specification consists of Class invariant Requires and ensures of the methods

Example, class invariant 1 public class HashSet { 2 private Object [] arr ; 3 int nobj ; 4 5 public void insert ( Object o) {... } 6... 7 } Class Invariant nobj should be equal to the number of non-null elements in arr, and for each index i in range of arr such that arr[i] is non-null, all elements between indices arr[i].hash() and i are non-null, and there are no two non-null elements of arr that are equal

Testing

Software testing What we look at here Systematic general rules for how to write test cases Repeatable be able to run tests over and over again What we don t look at here Running a program to see if anything goes wrong Letting a lot of people run the program to see if anything goes wrong (Beta-testing)

Testing on Different Levels Unit Testing testing a small unit of a system Requires that the behaviour of the unit has been specificied. In Java this often corresponds to testing a method or a class. Integration Testing testing the interaction between two or more units System Testing testing a whole system against the specification of its externally observable behaviour System testing is mostly useful for convincing about the correctness. Less useful for finding bugs because the infection phase going from defect to failure is usually complex and difficult to unwind. The code that is being tested is called the IUT (implementation under test).

Testing Non-Functional Requirements Not considered further Performance testing or load testing Stability testing Usability testing Security testing

When Should Testing Take Place? The sooner a bug is found, the better. So, testing should start early. Extreme case: Test-driven program development but Testing early means a lot of unit testing which requires a lot of specifications. But writing specifications for the units of a system is already needed for a large project when programming by contract. Tested units may be replaced later on, making the tests useless. On the other hand, writing and running tests often gives a deep understanding of the program. The need to replace the unit may have been realized during the testing activities.

Systematic testing Use precise methods to design correct tests Each individual test is called a test case Organize collections of related test cases in test suites Use precise methods to make sure that a test suite has a good coverage of the different cases of usage

Repeatable testing The basic idea is to write code that performs the tests. A tool can automatically run a large collection of tests The testing code can be integrated into the actual code, thus stored in an organised way When a bug has been fixed, the tests can be rerun to check if the failure is gone Whenever the code is extended, all old test cases can be rerun to check that nothing is broken (regression testing) JUnit is a small tool for writing and running test cases. It provides: Some functionality that is repeatedly needed when writing test cases A way to annotate methods as being test cases A way to run test cases automatically in a batch

Testing influences code Apart the obvious that testing should result in removal of bugs When writing specifications and test cases for units, the responsibilities of the different parts become clearer, which promotes good OO programming style (low coupling) In order to be able to test programs automatically, separating the IO and functionality becomes important

What does a test case consist of? Test case Initialisation (of class instance and input arguments) Call to the method of the IUT A test oracle which decides if the test succeeded or failed The test oracle is vital to run tests automatically

Demo Small demo showing basics of how to use JUnit

Summary, and what s next? Summary Specifications (motivation, contracts, pre- and postconditions, what to think about) Testing (motivation, different kinds of testing, role in software development, junit) What s next? More examples of test cases, presenting aspects of writing test cases and features of JUnit How to write a good test case? How to construct a good collection of test cases (test suite)?