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

Similar documents
Who is our rival? Upcoming. Testing. Ariane 5 rocket (1996) Ariane 5 rocket 3/8/18. Real programmers need no testing!

5) I want to get this done fast, testing is going to slow me down.

Therac-25 radiation therapy machine

Exceptions and Testing Michael Ernst Saman Amarasinghe

Testing. CSE 331 University of Washington. Michael Ernst

CSE 331 Software Design & Implementation

Announcements. Testing. Announcements. Announcements

CSE 331 Software Design & Implementation

Beta. Team Assessment. Exam. Exam stats. Things to remember. TesAng 3/23/15

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

Course&updates& Tes=ng& Ariane&5&rocket& Mars&Polar&Lander& Therac[25&radia=on&therapy&machine& 4/3/17& Real%programmers%need%no%tes/ng!

Testing. Prof. Clarkson Fall Today s music: Wrecking Ball by Miley Cyrus

1 Visible deviation from the specification or expected behavior for end-user is called: a) an error b) a fault c) a failure d) a defect e) a mistake

Chapter 11, Testing. Using UML, Patterns, and Java. Object-Oriented Software Engineering

Software Quality Assurance. David Janzen

People tell me that testing is

Lecture 15 Software Testing

Modern Methods in Software Engineering. Testing.

Overview. State-of-the-Art. Relative cost of error correction. CS 619 Introduction to OO Design and Development. Testing.

Chapter 8 Software Testing. Chapter 8 Software testing

Terminology. There are many different types of errors and different ways how we can deal with them.

Manuel Oriol, CHCRC-C, Software Testing ABB

Software Engineering 2 A practical course in software engineering. Ekkart Kindler

Second assignment came out Monday evening. Find defects in Hnefetafl rules written by your classmates. Topic: Code Inspection and Testing

An Introduction to Systematic Software Testing. Robert France CSU

Software Engineering Fall 2015 (CSC 4350/6350) TR. 5:30 pm 7:15 pm. Rao Casturi 11/10/2015

Testing Process and Methods. CS 490MT/5555, Spring 2017, Yongjie Zheng

Testing. UW CSE 160 Winter 2016

Software Engineering Fall 2014

Topics in Software Testing

Testing. ECE/CS 5780/6780: Embedded System Design. Why is testing so hard? Why do testing?

Software Engineering (CSC 4350/6350) Rao Casturi

International Journal of Computer Engineering and Applications, Volume XII, Special Issue, September 18, ISSN SOFTWARE TESTING

Topic: Software Verification, Validation and Testing Software Engineering. Faculty of Computing Universiti Teknologi Malaysia

CS 4387/5387 SOFTWARE V&V LECTURE 4 BLACK-BOX TESTING

Testing! Prof. Leon Osterweil! CS 520/620! Spring 2013!

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

Testing & Debugging TB-1

Aerospace Software Engineering

International Journal of Computer Engineering and Applications, Volume XII, Special Issue, April- ICITDA 18,

Introduction to Dynamic Analysis

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

Three General Principles of QA. COMP 4004 Fall Notes Adapted from Dr. A. Williams

Testing: Test design and testing process

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

Topics. Software Testing Test Driven Development Black Box Testing Unit Testing White Box Testing Coverage Testing Software Debugging

Equivalence Class Partitioning. Equivalence Partitioning. Definition and Example. Example set of classes

In this Lecture you will Learn: Testing in Software Development Process. What is Software Testing. Static Testing vs.

WHY TEST SOFTWARE?...

Coding and Unit Testing! The Coding Phase! Coding vs. Code! Coding! Overall Coding Language Trends!

(See related materials in textbook.) CSE 435: Software Engineering (slides adapted from Ghezzi et al & Stirewalt

XVIII. Software Testing. Laurea Triennale in Informatica Corso di Ingegneria del Software I A.A. 2006/2007 Andrea Polini

Sample Question Paper. Software Testing (ETIT 414)

MONIKA HEINER.

INTRODUCTION TO SOFTWARE ENGINEERING

Bridge Course On Software Testing

Software Testing. Software Testing

Software Testing Fundamentals. Software Testing Techniques. Information Flow in Testing. Testing Objectives

Part 5. Verification and Validation

QUIZ #5 - Solutions (5pts each)

Object-Oriented Software Engineering Conquering Complex and Changing Systems. Chapter 9, Testing

Chapter 10. Testing and Quality Assurance

Software Engineering Theory. Lena Buffoni (slides by Kristian Sandahl/Mariam Kamkar) Department of Computer and Information Science

Software Testing. Software Testing. in the textbook. Chapter 8. Verification and Validation. Verification Techniques

10. Software Testing Fundamental Concepts

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

Programming Embedded Systems

Verification and Validation. Verification and validation

Software Testing Interview Question and Answer

Why testing and analysis. Software Testing. A framework for software testing. Outline. Software Qualities. Dependability Properties

Quality Assurance in Software Development

Comparison Study of Software Testing Methods and Levels- A Review

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

Software Engineering

The Importance of Test

Verification and Validation

Software Engineering Testing and Debugging Testing

Summer May 11, 2010

Higher-order Testing. Stuart Anderson. Stuart Anderson Higher-order Testing c 2011

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

Module 1 : Fundamentals of Testing. Section 1: Manual Testing

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 15 Testing

Software Testing Lecture 1. Justin Pearson

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

Introduction to Problem Solving and Programming in Python.

Software Engineering and Scientific Computing

Verification, Testing, and Bugs

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

CS 520 Theory and Practice of Software Engineering Fall 2018

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

linaye/gl.html

C07: Testing and JUnit

Sample Exam. Certified Tester Foundation Level

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

Black-box Testing Techniques

SOFTWARE ENGINEERING IT 0301 Semester V B.Nithya,G.Lakshmi Priya Asst Professor SRM University, Kattankulathur

Testing. Outline. What is this? Terminology. Erroneous State ( Error ) Algorithmic Fault

Department of Electrical & Computer Engineering, University of Calgary. B.H. Far

CS 520 Theory and Practice of Software Engineering Fall 2018

Written exam TDDD04 Software Testing

Transcription:

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

Outline Software quality control Effective unit testing Coverage and regression testing 2

intro basics of software quality control

Errors and faults Ariane 5: 37 sec after launch. Cost: $1 billion. 4

Errors and faults Error: incorrect software behavior Example: Software controller for the Ariane 5 rocket crashed (and so did the rocket). Ariane 5: 37 sec after launch. Cost: $1 billion. 4

Errors and faults Error: incorrect software behavior Example: Software controller for the Ariane 5 rocket crashed (and so did the rocket). Fault: mechanical or algorithmic cause of error (bug) Example: Conversion from 64-bit floating point to 16-bit signed integer value caused an exception. Requirements specify desired behavior; if the system deviates from that, it has a fault. Ariane 5: 37 sec after launch. Cost: $1 billion. 4

Software quality control techniques Fault avoidance: prevents errors before the system is released. reviews, inspections, walkthroughs, development methodologies, testing, verification Fault tolerance: enables the system to recover from (some classes of) errors by itself. rollbacks, redundancy, mirroring 5

Showing the presence and absence of bugs testing verification 6

Showing the presence and absence of bugs Detects the presence of bugs by running the code on a few carefully chosen inputs. testing verification 6

Showing the presence and absence of bugs Detects the presence of bugs by running the code on a few carefully chosen inputs. Shows the absence of bugs on all possible inputs. testing verification 6

Common kinds of testing Unit testing: tests the behavior of an individual module (method, class, interface) Black-box testing White-box testing System testing: tests the behavior of the system as a whole, with respect to scenarios and requirements Functional testing, integration testing Performance, load, stress testing Acceptance, usability, installation, beta testing 7

effective unit testing

Two rules of unit testing Do it early and do it often Catch bugs quickly, before they have a chance to hide Automate the process if you can Be systematic If you thrash about arbitrarily, the bugs will hide in the corner until you're gone 9

Four basic steps of a test 1. Choose input data without looking at the implementation: black box with knowledge of the implementation: white box 2. Define the expected outcome 3. Run on the input to get the actual outcome 4. Compare the actual and expected outcomes 10

Four basic steps of a test 1. Choose input data without looking at the implementation: black box with knowledge of the implementation: white box 2. Define the expected outcome 3. Run on the input to get the actual outcome This is hard! Need a set of test cases that is small enough to run quickly, yet large enough to cover [all] interesting program behaviors. 4. Compare the actual and expected outcomes 10

Choosing inputs: two key ideas 11

Choosing inputs: two key ideas Partition the input space Identify subdomains with the same behavior Pick one input from each subdomain 11

Choosing inputs: two key ideas Partition the input space Identify subdomains with the same behavior Pick one input from each subdomain Boundary values Pick inputs at the edges of the subdomains. Effective at finding corner case bugs: off-by-one, overflow, aliasing, empty container 11

Partitioning the input space // returns the maximum of a, b public static int max(int a, int b) { } Partition into a < b, a = b, a > b Pick an input from each class (1, 2), (0, 0), (2, 1) 12

Partitioning the input space // returns the maximum of a, b public static int max(int a, int b) { } Partition into a < b, a = b, a > b Pick an input from each class (1, 2), (0, 0), (2, 1) How would you partition the input space for BigInteger multiplication? Set intersection? 12

Choosing boundary values // returns x public static int abs(int a) { } Partition into a < 0, a > 0, a = 0 (boundary) Other boundary values Integer.MAX_VALUE Integer.MIN_VALUE 13

Choosing boundary values // returns x public static int abs(int a) { } Partition into a < 0, a > 0, a = 0 (boundary) Other boundary values Integer.MAX_VALUE Integer.MIN_VALUE What are good boundary values for objects? 13

Black box testing Explores alternate paths through the specification. Module under test is a black box: interface visible, internals hidden. // If a >= b, returns a. Otherwise returns b. public static int max(int a, int b) { } 3 paths, so 3 subdomains (1, 2) => 2 (2, 1) => 2 (0, 0) => 0 14

Advantages of black box testing Process is not influenced by component being tested Assumptions embodied in code not propagated to test data. Robust with respect to changes in implementation Test data need not be changed when code is changed Allows for independent testers Testers need not be familiar with code 15

Disadvantage of black box testing It will miss bugs in the implementation that are not covered by the specification Control-flow details Performance optimizations Alternate algorithms for different cases 16

White box testing Explores alternate paths through the implementation Module under test is a clear box: internals visible. boolean[] primetable = new boolean[cache_size]; boolean isprime(int x) { if (x>cache_size) { for (int i=2; i<x/2; i++) { if (x%i==0) return false; } return true; } else { return primetable[x]; } } Important transition at around x = CACHE_SIZE 17

(Dis)advantages of white box testing 18

(Dis)advantages of white box testing Advantages Finds an important class of boundaries. Yields useful test cases. In isprime example, need to check numbers on each side of CACHE_SIZE CACHE_SIZE-1, CACHE_SIZE, CACHE_SIZE+1 18

(Dis)advantages of white box testing Advantages Finds an important class of boundaries. Yields useful test cases. In isprime example, need to check numbers on each side of CACHE_SIZE Disadvantages CACHE_SIZE-1, CACHE_SIZE, CACHE_SIZE+1 Tests may have the same bugs as implementation! 18

Properties of good and bad unit tests Tests should be self-contained and not depend on each other implicitly or explicitly. "Smells" (bad things to avoid) in tests: Constrained test order Test A must run before Test B. Tests call each other Test A calls Test B. Mutable shared state Tests A/B both use a shared object. 19

coverage and regression testing

Measuring test suite quality with coverage 21

Measuring test suite quality with coverage Various kinds of coverage Statement: is every statement run by some test case? Branch: is every direction of an if or while statement (true or false) taken by some test case? Path: is every path through the program taken by some test case? 21

Measuring test suite quality with coverage Various kinds of coverage Statement: is every statement run by some test case? Branch: is every direction of an if or while statement (true or false) taken by some test case? Path: is every path through the program taken by some test case? Limitations of coverage Coverage is just a heuristic. 100% coverage may not be achievable. High-cost to approach the limit. 21

Measuring test suite quality with coverage Various kinds of coverage Statement: is every statement run by some test case? Branch: is every direction of an if or while statement (true or false) taken by some test case? Path: is every path through the program taken by some test case? Limitations of coverage Coverage is just a heuristic. 100% coverage may not be achievable. High-cost to approach the limit. We will ask you to provide test-suite coverage metrics for your Feature-Complete Release. 21

Coverage measuring tools: EclEmma 22

Regression testing 23

Regression testing Whenever you find a bug Store the input that elicited that bug, plus the correct output Add these to the test suite Check that the test suite fails Fix the bug and verify the fix 23

Regression testing Whenever you find a bug Store the input that elicited that bug, plus the correct output Add these to the test suite Check that the test suite fails Fix the bug and verify the fix Why is this a good idea? Ensures that your fix solves the problem. Helps to populate test suite with good tests. Protects against reversions that reintroduce bug: It happened at least once, and it might happen again 23

Summary Unit testing helps convince others that a module works; catch problems earlier. Choose test data to cover specification (black box testing) code (white box testing) Testing can t generally prove the absence of bugs, but it can increase quality and confidence in the implementation. 24