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

Similar documents
Lecture 15 Software Testing

CS159. Nathan Sprague. September 30, 2015

Software Testing CS 408

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

Object-Oriented Software Engineering Practical Software Development using UML and Java

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

Chapter 8 Software Testing. Chapter 8 Software testing

Darshan Institute of Engineering & Technology for Diploma Studies

Software Testing. Software Testing

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

Testing & Continuous Integration. Kenneth M. Anderson University of Colorado, Boulder CSCI 5828 Lecture 20 03/19/2010

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

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

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

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

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

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

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

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

Examination Questions Time allowed: 1 hour 15 minutes

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

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

Chapter 9. Software Testing

Program Correctness and Efficiency. Chapter 2

Ingegneria del Software Corso di Laurea in Informatica per il Management

Testing & Debugging TB-1

Testing. Topics. Types of Testing. Types of Testing

Testing Theory. Agenda - What will you learn today? A Software Life-cycle Model Which part will we talk about today? Theory Lecture Plan

Manuel Oriol, CHCRC-C, Software Testing ABB

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

Software Engineering. Unit Testing Gobo Eiffel Test and Clover

People tell me that testing is

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

Question 1: What is a code walk-through, and how is it performed?

10. Software Testing Fundamental Concepts

An Introduction to Systematic Software Testing. Robert France CSU

Agile Software Development. Lecture 7: Software Testing

UNIT-4 Black Box & White Box Testing

CS Programming I: Arrays

COPYRIGHTED MATERIAL. Index

Introduc)on to tes)ng with JUnit. Workshop 3

Testing. UW CSE 160 Winter 2016

QUIZ #5 - Solutions (5pts each)

Aerospace Software Engineering

Verification and Validation

Verification Overview Testing Theory and Principles Testing in Practice. Verification. Miaoqing Huang University of Arkansas 1 / 80

Sample Exam Syllabus

Software Testing. Lecturer: Sebastian Coope Ashton Building, Room G.18

CSCE 747 Unit Testing Laboratory Name(s):

Software Testing part II (white box) Lecturer: Giuseppe Santucci

UNIT-4 Black Box & White Box Testing

Verification and Validation. Verification and validation

Risk-Based Testing & Test-Driven Development

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

Software Testing: Introduction

ECSE 321 Assignment 2

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

Testing. Christopher Simpkins Chris Simpkins (Georgia Tech) CS 2340 Objects and Design CS / 13

Testing and Debugging

Chapter 9 Quality and Change Management

Pearson Education 2007 Chapter 9 (RASD 3/e)

INTRODUCTION TO SOFTWARE ENGINEERING

MTAT : Software Testing

Topics in Software Testing

Software Quality Assurance. David Janzen

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

Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

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

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

Unit Testing with JUnit and CppUnit

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

Software Engineering

MTAT : Software Testing

Mainline Functional Testing Techniques

Chapter 8 Software Testing. Chapter 8 So-ware tes0ng

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

Software Engineering Testing and Debugging Testing

Introduction to Problem Solving and Programming in Python.

Object-Oriented Design Lecture 5 CSU 370 Fall 2008 (Pucella) Friday, Sep 26, 2008

linaye/gl.html

EECS 4313 Software Engineering Testing. Topic 01: Limits and objectives of software testing Zhen Ming (Jack) Jiang

Write perfect C code to solve the three problems below.

C07: Testing and JUnit

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

CS 520 Theory and Practice of Software Engineering Fall 2018

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

Software-Architecture Unit Testing (JUnit)

Test design techniques

Unit Testing as Hypothesis Testing

Lecture 6. Drinking. Nested if. Nested if s reprise. The boolean data type. More complex selection statements: switch. Examples.

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

Unit Testing as Hypothesis Testing

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

Introduction to Dynamic Analysis

Testing: Test design and testing process

Section 1.2: What is a Function? y = 4x

Chapter 7 Control Statements Continued

1 Black Box Test Data Generation Techniques

Software Testing CS 408. Lecture 11: Review 2/20/18

Finding Firmware Defects Class T-18 Sean M. Beatty

Transcription:

Supplemental Materials: Software esting CS2: Data Structures and Algorithms Colorado State University Chris Wilcox, Russ Wakefield, Wim Bohm, Dave Matthews opics Software esting est Driven Development Black Box esting Unit esting White Box esting Coverage esting Software Debugging Defects and Reliability Software Defects: are inevitable in a complex software system. In industry: 10-50 bugs per 1000 lines of code! Defects can be obvious or remain hidden. Software Reliability: What is the probability of failure of a software package over time: Measurements: mean time between failures, crash statistics, uptime versus downtime. 1 2 3 1

Common faults in algorithms Incorrect logical conditions Calculation performed in wrong place Non-terminating loop or recursion Incorrect preconditions for an algorithm Not handling null conditions Off-by-one errors Operator precedence errors Numerical faults in algorithms Not using enough bits or digits Not using enough places before or after the decimal point Assuming a floating point value will be exactly equal to some other value Ordering operations poorly so errors build up Other faults in algorithms Poor minimal configuration performance Handling peak loads or missing resources HW and SW configuration incompatibility Crash recovery Deadlock, livelock, and critical races Inappropriate resource management 4 5 6 2

Definition Software esting is a systematic attempt to reveal errors in software by running test programs or scripts (interactively or automated). AILING ES: an error was demonstrated in the software under test. PASSING ES: no error was found, at least for this particular situation. heory of testing says you cannot prove absence of all defects in software. 7 Exhaustive esting? We consider a program to be correct if it produces the expected output for all inputs. Domain of input values can be very large, e.g. 2 32 values for an integer or float: int divide (int operand1, int operand2); 2 32 * 2 32 = 2 64, a large number, so we clearly cannot test exhaustively! And that is just for one method, in one class, in one package, and relatively simple. 8 Software esting ypes unctional, Configuration, Usability, Reliability, Performance, Compatibility, Error, Localization,... Processes est-driven Development, Coverage esting, Automated esting, Regression esting, Methods Black-box, white-box Levels Unit (Method), Module (Class), Integration, System 9 3

unctional esting wo Kinds of ests est Driven Development ests that find defects after they occur a waste of time ests that prevent defects the only kind to create Goal: Clean code that works! Drive development with automated tests write new code only if tests fail eliminate duplication Implies a different order of tasks - write a little test first - make the test work quickly - eliminate any resulting duplications 10 Citation: Study of the oyota Production System, Shigeo Shingo 11 Citation: est Driven Development, Kent Beck 12 4

est Driven Development Program testing methods Black-box esting 13 Black-box testing Specifications drive test inputs and expected outputs Code, design or internal documents unavailable White-box testing Code structure drives test inputs Specifications used to derive expected outputs Code, design, and internal documents available 14 Specifications drive test inputs and expected outputs Code, design or internal documents unavailable 15 5

Equivalence classes Groups of inputs to be treated similarly Numbers: <0, 0, >0 Numbers: <0, 0..1, >1 Months: [-..0], [1..12], [13.. ] Months: Jan, eb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec, any other 3 character string. Years: <0, [0..99], >99 Years: <0, [0..9999], >9999 16 Equivalence partition testing est at least one value of every equivalence class for each individual input. est all combinations where one input is likely to affect the interpretation of another input. est random combinations of equivalence classes. 17 Boundary value testing Expand equivalence classes to test values at extremes of each equivalence class. Number ranges: minimum, slightly above minimum, nominal or median value, slightly below maximum, and maximum values values slightly and significantly outside the range 18 6

Boundary Value esting Example est boundaries of the parameter value domain: Unit esting JUnit is a simple, open source framework to write and run repeatable tests. JUnit is commonly used in industry for unit testing. eatures include: Assertions for testing expected results est fixtures for sharing common test data est runners for running tests JUnit value assertions assertrue( 'a' < 'b', "message"); assertalse( 'b' < 'a' ); assertequals( 1+1, 2 ); assertequals( 22.0d/ 7.0d, 3.14159, 0.001 ); assertequals( "cs165", "cs165" ); 19 Citation: JUnit testing framework (http://www.junit.org/) 20 Citation: JUnit testing framework (http://www.junit.org/) 21 7

JUnit array assertions JUnit other assertions JUnit test class int[] array1 = { 1, 2, 3 ; int[] array2 = { 1, 2, 3 ; Stack<Object> stack = new Stack<>(); import static org.junit.jupiter.api.assertions.assertequals; import org.junit.jupiter.api.est; assertnull( null ); assertnotnull( array1 ); assertnotsame( array1, array2 ); assertarrayequals( array1, array2 ); asserthrows(emptystackexception.class, () -> stack.pop()); asserthrows(emptystackexception.class, () -> stack.peek()); class irstjunit5ests { @est void myirstest() { assertequals(2, 1 + 1); Citation: JUnit testing framework (http://www.junit.org/) 22 Citation: JUnit testing framework (http://www.junit.org/) 23 Citation: JUnit testing framework (http://www.junit.org/) 24 8

est Driven Development Example RED Make it work class Example { class Example { /* Performs requested operations on a value * @param x is an integer input value * @param c1 is a boolean that increments the input value if true * @param c2 is a boolean that squares the input value if true * @param c3 is a boolean that negates the input value if true * @return the modified input value */ int xmpl( int x, boolean c1, boolean c2, boolean c3) { return 0; import org.junit.est; import static org.junit.assert.assertequals; /* est example function*/ class estexample{ @est public void testdonothing() { assertequals(2, Example.xmpl( 2, false, false, false )); /* Performs requested operations on a value * @param x is an integer input value * @param c1 is a boolean that increments the input value if true * @param c2 is a boolean that squares the input value if true * @param c3 is a boolean that negates the input value if true * @return the modified input value */ int xmpl( int x, boolean c1, boolean c2, boolean c3) { return x; 25 26 27 9

RED Make it work RED class Example { import org.junit.est; import static org.junit.assert.assertequals; /* est example function*/ class estexample{ @est public void testincrement() { assertequals(1, Example.xmpl( 0, true, false, false )); assertequals(3, Example.xmpl( 2, true, false, false )); /* Performs the requested operations on a value * @param x is an integer input value * @param c1 is a boolean that increments the input value if true * @param c2 is a boolean that squares the input value if true * @param c3 is a boolean that negates the input value if true * @return the modified integer input value */ int xmpl( int x, boolean c1, boolean c2, boolean c3) { if ( c1 ) x++; return x; import org.junit.est; import static org.junit.assert.assertequals; /* est example function*/ class estexample{ @est public void testsquare() { assertequals(0, Example.xmpl( 0, false, true, false )); assertequals(4, Example.xmpl( 2, false, true, false )); 28 29 30 10

Make it work RED Make it work class Example { class Example { /* Performs requested operations on a value * @param x is an integer input value * @param c1 is a boolean that increments the input value if true * @param c2 is a boolean that squares the input value if true * @param c3 is a boolean that negates the input value if true * @return the modified input value */ int xmpl( int x, boolean c1, boolean c2, boolean c3) { if ( c1 ) x++; if ( c2 ) x *= x; return x; import org.junit.est; import static org.junit.assert.assertequals; /* est example function*/ class estexample{ @est public void testnegate() { assertequals( 0, Example.xmpl( 0, false, false, true)); assertequals(-2, Example.xmpl( 2, false, false, true)); /* Performs requested operations on a value * @param x is an integer input value * @param c1 is a boolean that increments the input value if true * @param c2 is a boolean that squares the input value if true * @param c3 is a boolean that negates the input value if true * @return the modified input value */ int xmpl( int x, boolean c1, boolean c2, boolean c3) { if ( c1 ) x++; if ( c2 ) x *= x; if ( c3 ) x = -x; return x; 31 32 33 11

RED import org.junit.est; import static org.junit.assert.assertequals; /* est example function*/ class estexample{ @est public void testcombination() { assertequals(-9, Example.xmpl( 2, true, true, true)); 34 White-Box esting White-box testing Code structure drives test inputs Specification used to derive tests outputs Code, design, and internal documentation are available Goal is to cover the code to gain confidence and detect defects. 35 White Box esting Statement Coverage (most common) Requires all statements to be executed Branch Coverage Require decisions evaluate to true and false at least once Implies statement coverage Path Coverage (least common) Require all possible paths to be executed Implies branch coverage 36 12

Coverage Problems Statement May not exercise all the conditions in condition predicates Branch May not exercise all combinations of branches Path combinatorial explosion infinite paths for loops not all paths are feasible 37 1 public class Example { 2 public int xmpl( int x, boolean c1, boolean c2, boolean c3) { 3 if (c1) 4 x++; 5 if (c2) 6 x *= x; 7 if (c3) 8 x = -x; 9 return x; 10 11 Statement Coverage All statements must be executed. What tests are required? 38 2 3 5 7 9 4 6 8 Statement Coverage import org.junit.est; import static org.junit.assert.assertequals; /* est example function*/ class estexample{ @est public void statementcoverage() { assertequals(-9, Example.xmpl( 2, true, true, true)); 39 13

1 public class Example { 2 public int xmpl( int x, boolean c1, boolean c2, boolean c3) { 3 if (c1) 4 x++; 5 if (c2) 6 x *= x; 7 if (c3) 8 x = -x; 9 return x; 10 11 Branch Coverage All decisions must evaluate to both true and false. What tests are required? 2 3 5 7 9 4 6 8 Branch Coverage import org.junit.est; import static org.junit.assert.assertequals; /* est example function*/ class estexample{ @est public void branchcoverage() { assertequals( 2, Example.xmpl( 2, false, false, false )); assertequals(-9, Example.xmpl( 2, true, true, true)); 1 public class Example { 2 public int xmpl( int x, boolean c1, boolean c2, boolean c3) { 3 if (c1) 4 x++; 5 if (c2) 6 x *= x; 7 if (c3) 8 x = -x; 9 return x; 10 11 Path Coverage All paths must be executed. What tests are required? 2 3 5 7 9 4 6 8 40 41 42 14

Path Coverage class estexample{ @est public void pathcoverage() { assertequals( 2, Example.xmpl( 2, false, false, false )); assertequals( 3, Example.xmpl( 2, true, false, false )); assertequals( 4, Example.xmpl( 2, false, true, false )); assertequals(-2, Example.xmpl( 2, false, false, true)); assertequals( 9, Example.xmpl( 2, true, true, false )); assertequals(-3, Example.xmpl( 2, true, false, true)); assertequals(-4, Example.xmpl( 2, false, true, true)); assertequals(-9, Example.xmpl( 2, true, true, true)); 43 Code Coverage Code coverage improves software quality by illumination: it shines light on executed code, and reveals dark corners that are untested or never used. his software metric can enhance many projects, from standard business apps to those with ultra-low tolerance for error, for example medical devices. Citation: Emma code coverage tool (http://emma.sourceforge.net/) 44 Code Coverage = executed, Yellow = partial, = not executed Citation: Emma code coverage tool (http://emma.sourceforge.net/) 45 15

Software Debugging Possible methods for debugging: Using debugger Print debugging Examining code IDEs have built-in debuggers Computer Science department has print debugging package Debug.java Code inspections done by teams in industry Print Debugging Debugging ools 46 47 48 16