Software Testing See also Sommerville, Chapter 8 Amman and Offut, Introduction to Software Testing, Cambridge University Press, 2008.

Slides:



Advertisements
Similar presentations
LECTURE 8: Software Testing
Advertisements

Chapter 14 Software Testing Techniques - Testing fundamentals - White-box testing - Black-box testing - Object-oriented testing methods (Source: Pressman,
Software Testing. Quality is Hard to Pin Down Concise, clear definition is elusive Not easily quantifiable Many things to many people You'll know it when.
Defect testing Objectives
JUnit Tutorial Hong Qing Yu Nov JUnit Tutorial The testing problems The framework of JUnit A case study JUnit tool Practices.
Unit Testing Australian Development Centre Brisbane, Australia.
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
Lecture 3 Black-box Testing. Test cases are constructed without reference to the code structure +Can test the requirements not the code + Can overcome.
Lecture 8: Testing, Verification and Validation
White Box and Black Box Testing Tor Stålhane. What is White Box testing White box testing is testing where we use the info available from the code of.
SOFTWARE TESTING. INTRODUCTION  Software Testing is the process of executing a program or system with the intent of finding errors.  It involves any.
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.
Unit and Functional Testing with JUnit and Related Tools Greg Barnes University of Washington
Lecture 2 White-box Testing and Structural Coverage.
Approach of Unit testing with the help of JUnit Satish Mishra
Testing and Debugging CS221 – 2/13/09. Airline Program.
JUnit. What is unit testing? A unit is the smallest testable part of an application. A unit test automatically verifies the correctness of the unit. There.
7. Goals of Software Design Design faces many challenges to produce a good product, e.g. shifting requirements. But what do we mean by good ? We need some.
JUnit Tutorial. Automating Testing Process Testing is boring and time-consuming, it is not a job for “human” Why not automating the testing process? Test.
Testowanie kodu Bartosz Baliś, Na podstawie prezentacji Satisha Mishra Iana Sommerville Erica Braude.
Software Testing. “Software and Cathedrals are much the same: First we build them, then we pray!!!” -Sam Redwine, Jr.
Presentation Outline What is JUnit? Why Use JUnit? JUnit Features Design of JUnit Downloading JUnit Writing Tests – TestCase – TestSuite Organizing The.
George Blank University Lecturer. JUnit for Test Driven Development By Vivek Bhagat, George Blank.
1 Functional Testing Motivation Example Basic Methods Timing: 30 minutes.
January 27, 2002 ECEN5033 University of Colorado -- Class Testing 1 Specifying interactions Remainder of slides assume Operations defined by a class are.
Software Testing Sudipto Ghosh CS 406 Fall 99 November 9, 1999.
Dr. Pedro Mejia Alvarez Software Testing Slide 1 Software Testing: Building Test Cases.
Lesson 7 Unit Testing /JUnit/ AUBG ICoSCIS Team Assoc. Prof. Stoyan Bonev March, , 2013 SWU, Blagoevgrad.
JUnit The framework. Goal of the presentation showing the design and construction of JUnit, a piece of software with proven value.
Lecture 6 Software Testing and jUnit CS140 Dick Steflik.
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.
Computer Science and Engineering College of Engineering The Ohio State University JUnit The credit for these slides goes to Professor Paul Sivilotti at.
CMSC 345 Fall 2000 Unit Testing. The testing process.
Unit testing Unit testing TDD with JUnit. Unit Testing Unit testing with JUnit 2 Testing concepts Unit testing Testing tools JUnit Practical use of tools.
Introduction to Software Testing. Types of Software Testing Unit Testing Strategies – Equivalence Class Testing – Boundary Value Testing – Output Testing.
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 22 Slide 1 Software Verification, Validation and Testing.
Software Construction Lecture 18 Software Testing.
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
CSC 480 Software Engineering Lecture 15 Oct 21, 2002.
1 Introduction to Software Testing. Reading Assignment P. Ammann and J. Offutt “Introduction to Software Testing” ◦ Chapter 1 2.
1 Ch. 1: Software Development (Read) 5 Phases of Software Life Cycle: Problem Analysis and Specification Design Implementation (Coding) Testing, Execution.
A tool for test-driven development
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.
EMBEDDED REAL-TIME, INC. December 8, 2015 Java Unit Mark Mosher Rochester Java Users Group.
CPSC 873 John D. McGregor Session 9 Testing Vocabulary.
JUnit A framework which provides hooks for easy testing of your Java code, as it's built Note: The examples from these slides can be found in ~kschmidt/public_html/CS265/Labs/Java/Junit.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 11, Testing.
S Ramakrishnan1 Systems V & V, Quality and Standards Dr Sita Ramakrishnan School CSSE Monash University.
Unit Testing CSSE 514 Programming Methods 4/19/01.
Test a Little, Code a Little Colin Sharples IBM Global Services New Zealand Colin Sharples IBM Global Services New Zealand.
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
Dynamic Testing.
Testing Overview Software Reliability Techniques Testing Concepts CEN 4010 Class 24 – 11/17.
SOFTWARE TESTING LECTURE 9. OBSERVATIONS ABOUT TESTING “ Testing is the process of executing a program with the intention of finding errors. ” – Myers.
Getting Started with JUnit Getting Started with JUnit The benefits and ease of writing and running JUnit test cases and test suites. The benefits and ease.
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Software Testing.
Software Construction Lab 10 Unit Testing with JUnit
Software Testing.
Software Testing and Maintenance 1
Input Space Partition Testing CS 4501 / 6501 Software Testing
Computer Science 209 Testing With JUnit.
Structural testing, Path Testing
Chapter 11, Testing.
Testing Overview References:
CSE 303 Concepts and Tools for Software Development
Test Case Test case Describes an input Description and an expected output Description. Test case ID Section 1: Before execution Section 2: After execution.
Chapter 11: Integration- and System Testing
CSE 1020:Software Development
Presentation transcript:

Software Testing See also Sommerville, Chapter 8 Amman and Offut, Introduction to Software Testing, Cambridge University Press, 2008.

Testing Most basic form of post-hoc SQA Helps define program functionality Can be used as documentation (c.f. XP) Must ensure program is testable (c.f. PSS docs) Methods become callable Modules get looser coupling

Basic Terminology The system under test (SUT) can be of different types (procedural, reactive, etc.) A test case consists of a single input for the SUT A verdict is a judgment after a test case terminates – pass/fail/warning/dont know An oracle is a method to produce verdicts A test suite is a set of test cases How much have we tested? – coverage measures!

User Requirements Software Requirements Architecture Design Detailed design & CodingUnit Testing Integration testing The V model Integrates design and testing Time Test cases 4 System testing Acceptance testing Test cases

Structural Testing (Glass or white box) An error must exist along a path If tests dont exercise that path then error can never be observed So identify and exercise each path No loops – finitely many paths – good! Loops – infinitely many paths – bad! Loops + branches – exponential growth in path numbers with loop depth – very bad !!!!

Structural Testing - Problems What about sins of omission? – no path to go down! What about dead code – is a path possible? How to avoid redundant testing?

Condensation Graph Assignments1 Assignments2 Assignments3Assignments4 Halt Start Cond1 Cond2 Path analysis: 1&3, 1&4, 1&2&3, 1&2&4 …etc

Structural Testing Requirements These are structural requirements on a test suite They ignore functionality! Easy to define using graph theory Possible to automate generation by constraint solving Easy to measure coverage!

Graph Coverage A path is a sequence of nodes n 0,…, n k in a (condensation) graph G, such that each adjacent node pair, (n i, n i+1 ) forms an edge in G. A test requirement tr(.) is a predicate on paths – Node n ( p ) p has node n – Edge e (p) p has edge e

Graph Coverage Definition: Given a set TR of test requirements for a graph criterion C, A test suite T satisfies C on graph G if, and only if for every test requirement tr(.) TR, there is at least one path p in G such that tr(p) is true (i.e. p satisfies tr(.))

Why so Formal? Answer: Sometimes coverage properties become very technical to define for efficiency reasons.

Structural Coverage Criteria (Amman and Offut, Chapter 2) 2.1. Node Coverage (NC) TR contains each reachable node in G Edge Coverage (EC) TR contains each reachable path of length Edge-Pair Coverage (EPC) TR contains each reachable path of length 2.

2.7. Complete Path Coverage (CPC) TR contains all paths in G Specified Path Coverage (SPC) TR contains a set S of test paths, where S is supplied as a parameter. Example. S contains paths that traverse every loop free path p in G and every loop in G both 0 and 1 times.

Functional Testing (Black-box Testing) Black-box = structure of code is invisible +Tests the specification not the code + Insensitive to code refactoring -Hard to find test verdicts – aka oracle problem -Hard to define coverage -Huge volume of testing – user profiles? -Use cases are an excellent source of tests

Random Testing Generate input vectors (or sequences) at random, fire into system and observe. Easy or tricky to implement – Low level data types … e.g. Int … easy – High level data types … e.g. graphs … tricky High volume of test cases … but is that good structural coverage? Good for low input dimension 1-5? – But poor for high input dimension

Random Testing Oracle step is difficult to automate without precise requirements Set up and tear down must also be considered Does random distribution match expected distribution? Are some data combinations meaningless? Data interdependencies and constraints! – Example consider calendar combinations: – Year/month/day/day of week – 1961/02/29/Wednesday … is this legal or not? Can try to filter out bad data but this can be very slow

k-wise testing Some components have fixed input size k e.g. a method myMethod(X:string,Y:char,Z:int) We need test vectors of length k i.e. ( i 1, …, i k ) Choose (say) C=10 input values V i = v i 1,…,v i c for each 1 i k Test suite S k is all combinations of V 1,…, V k Cartesian Product S = V 1 … V k Test suite size S is then C k = 10 k Probably not feasible for S 10,000

Example Suppose k = 3, C = 2, then C k = 2 3 = 8 V 1 = Sat, Sun V 2 = A, B V 3 = 1, 2 S 3 = (Sat, A, 1), (Sun, A, 1), (Sat, B, 1), (Sun, B, 1), (Sat, A, 2), (Sun, A, 2), (Sat, B, 2), (Sun, B, 2) Clearly S 3 has size 8 In general S k has size C k which is exponential in k.

n-Wise Testing – for nk For 1 ik, let c i be a fixed value from V i An n-wise test is a vector ( i 1, …, i k ) such that n elements are chosen from V 1,…, V k and the rest are chosen from c 1, …, c k. Let S n be the set of all n-wise tests.

Example: 1-wise testing Suppose n = 1 and let c 1 = Sat, c 2 = A, c 3 = 1 V 1 = Sat, Sun V 2 = A, B V 3 = 1, 2 S 1 = (Sat, A, 1), (Sun, A, 1), (Sat, B, 1), (Sat, A, 2) Clearly S 1 has size k*(C-1)+1 which is linear in k. So S 1 is small but has limited coverage.

Example: 2-wise testing (aka all-pairs or pairwise testing) Suppose n = 2 and c 1 = Sat, c 2 = A, c 3 = 1 V 1 = Sat, Sun V 2 = A, B V 3 = 1, 2 S 2 = (Sat, A, 1), (Sun, A, 1), (Sat, B, 1), (Sun, B, 1) (Sat, A, 2), (Sun, A, 2), (Sat, B, 2) Clearly S 2 has size 7 which is not much smaller than S 3. In general S 2 is much smaller than S k. S 2 grows O(C 2 ), which is much slower than C k !

Why Pairwise Testing? Bugs involving interactions between three or more parameters are progressively less common[2]. NASA database application. 67 percent of the failures were triggered by only a single parameter value, 93 percent by two- way combinations, and 98 percent by three-way combinations [13]. 10 UNIX commands. Cohen et al. showed that the pairwise tests gave over 90 percent block coverage [9]. Medical software devices. Only 3 of 109 failure reports indicated that more than two conditions were required to cause the failure [14].

Why Pairwise Testing Browser and server. More than 70 percent of bugs were detected with two or fewer conditions (75 percent for browser and 70 percent for server) and approximately 90 percent of the bugs reported were detected with three or fewer conditions (95 percent for browser and 89 percent for server) [13]. User interface software at Telcordia. Studies [8] showed that most field faults were caused by either incorrect single values or by an interaction of pairs of values. Their code coverage study also indicated that pairwise coverage is sufficient for good code coverage. Established tools, e.g. PICT See

Test Cases from Use Cases Instantiate a scenario with concrete data values, and expected results. Different flows lead to different use cases – Sunny day and rainy day scenarios Use graph coverage to measure use case coverage Structured and easy to use Natural focus on most significant use cases Good approach to system and acceptance testing, but may be difficult and unit and integration levels

UseCaseName: PurchaseTicket Precondition: The passenger is standing in front of ticket distributor and has sufficient money to purchase a ticket. Sequence: 1.The passenger selects the number of zones to be travelled, If the passenger presses multiple zone buttons, only the last button pressed is considered by the distributor. 2.The distributor displays the amount due 3.The passenger inserts money

4. The passenger selects a new zone before inserting sufficient money, the distributor returns all the coins and bills inserted by the passenger 5. If the passenger inserted more money than the amount due the distributor returns excess change. 6. The distributor issues ticket. 7. The passenger picks up the change and ticket.

TestCaseName: PurchaseTicket_SunnyDay Precondition: The passenger is standing in front of ticket distributor and has two 5 notes and 3 * 10 Cent coins Sequence: 1. The passenger presses in succession the zone buttons 2, 4, 1 and 2 2. The distributor should display in succession the fares , 0.75 and The passenger inserts a 5 note 4. The distributor returns 3*1 coins, 75Cent and a 2-zone ticket.

Postcondition The passenger has one 2-zone ticket We should also derive test cases that exercise rainy day scenarios (when something goes wrong) to test robustness.

Unit Testing with JUnit Developed by the XP community 2002 Framework for automating the execution of unit test for Java classes Write new test cases by subclassing the TestCase class Organise TestCases into TestSuites Automates testing process Built around Command and Composite patterns

Why use Junit? Junit tightly integrates development and testing, supports the XP approach Allows you to write code faster while increasing quality (???) – Can refactor code without worrying about correctness JUnit is simple. – Easy as running the compiler on your code

JUnit tests check their own results (oracle step) and provide immediate feedback – No manual comparison of expected with actual – Simple visual feedback JUnit tests can be composed into a hierarchy of test suites – Can run tests for any layer in the hierarchy Writing JUnit tests is inexpensive – No harder than writing a method to exercise the code JUnit tests increase the stability of software – More tests = more stability

Junit tests are developer tests – Tests fundamental building blocks of system – Tests delivered with code as a certified package Junit tests are written in Java – Seamless bond between test and code under test – Test code can be refactored into software code and vice-versa – Data type compatibility (float, double etc.) Junit is free

Junit Design A TestCase is a Command object A class of test methods subclasses TestCase A TestCase has public testXXX() methods To check expected with actual output invoke assert() method Use setUp() and tearDown() to prevent side effects between subsequent testXXX() calls

Test Run(TestResult) Test run(TestResult) setUp() tearDown() runTest() TestSuite addTest() Run(TestResult) Test setUp() tearDown() run(TestResult) testName:String

TestCase objects can be composed into TestSuite hierarchies. Automatically invoke all the testXXX() methods in each object A TestSuite is composed of TestCase instances or other TestSuite instances Nest to arbitrary depth Run whole TestSuite with a single pass/fail result Get your own installation instructions

Writing a Test Case Define a subclass of TestCase Override the setUp() method to intialise object(s) under test Optionally override the tearDown() method to release objects under test Define 1 or more public testXXX() methods hat exercise the object(s) under test and assert expected results

Import junit.framework.TestCase Public class ShoppingCartTest extends TestCase Private ShoppingCart cart; Private Product book1; Protected void setUp() Cart = new ShoppingCart(); Book1 = new Product(myTitle, 50); Cart.addItem(book1)

Protected void tearDown() //release objects under test here if necessary Public void testEmpty() Cart.empty(); // empty out cart assertEquals(0,cart.getItemCount() );

Public void testAddItem() Product book2 = new Product(title2, 65); cart.addItem(book2); double expectedBalance = book1.getPrice() + book2.getPrice(); assertEquals(expectedBalance, cart.getBalance()); assertEquals(2, cart.getItemCount() );

Public void testRemoveItem() throws productNotFoundException Cart.removeItem(book1); assertEquals(1, cart.getItemCount() ); Public void testRemoveItemNotInCart() try Product book3 = new Product(title3, 10); Cart.removeItem(book3); fail(should raise a ProductNotFoundException); Catch(ProductNotFoundException expected) //passed the test! // of class ShoppingCartTest