Class Testing Software Engineering of Standalone Programs University of Colorado, Boulder.

Slides:



Advertisements
Similar presentations
Test Yaodong Bi.
Advertisements

Formal Methods in Software Engineering
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
Class Testing ECEN5033 University of Colorado. January 27, 2002 ECEN5033 University of Colorado -- Class Testing 2 Overview Class Testing Testing Interactions.
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.
CMSC 345, Version 11/07 SD Vick from S. Mitchell Software Testing.
1 Software Testing and Quality Assurance Lecture 12 - The Testing Perspective (Chapter 2, A Practical Guide to Testing Object-Oriented Software)
1 Software Testing and Quality Assurance Lecture 21 – Class Testing Basics (Chapter 5, A Practical Guide to Testing Object- Oriented Software)
Software Testing and Quality Assurance
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 23 Slide 1 Software testing.
November 13, 2006ECEN 5543 / CSCI 5548 – Testing OO University of Colorado, Boulder 1 Testing Object-Oriented Software Principles Summary ECEN 5543 / CSCI.
January 27, 2002 ECEN5033 University of Colorado -- Class Testing 1 Adequacy of a Class Test Suite Ideally – exhaustively test each class Practically –
1 Software Testing and Quality Assurance Lecture 15 - Planning for Testing (Chapter 3, A Practical Guide to Testing Object- Oriented Software)
1 Software Testing and Quality Assurance Lecture 20 – Class Testing Basics (Chapter 5, A Practical Guide to Testing Object- Oriented Software)
© Copyright Eliyahu Brutman Programming Techniques Course.
1 Software Testing and Quality Assurance Lecture 14 - Planning for Testing (Chapter 3, A Practical Guide to Testing Object- Oriented Software)
Test Design Techniques
January 27, 2002 ECEN5033 University of Colorado -- Class Testing 1 Specifying interactions Remainder of slides assume Operations defined by a class are.
These slides are designed to accompany Software Engineering: A Practitioner’s Approach, 7/e (McGraw-Hill 2009). Slides copyright 2009 by Roger Pressman.1.
1 Object-Oriented Testing CIS 375 Bruce R. Maxim UM-Dearborn.
University of Palestine software engineering department Testing of Software Systems Fundamentals of testing instructor: Tasneem Darwish.
TESTING.
CMSC 345 Fall 2000 Unit Testing. The testing process.
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.
CSC 480 Software Engineering Lecture 14 Oct 16, 2002.
Overview of Software Testing 07/12/2013 WISTPC 2013 Peter Clarke.
1 Analysis Extracting from Use Cases to Create Diagrams.
CSC 395 – Software Engineering Lecture 13: Object-Oriented Analysis –or– Let the Pain Begin (At Least I’m Honest!)
Low-Level Detailed Design SAD (Soft Arch Design) Mid-level Detailed Design Low-Level Detailed Design Design Finalization Design Document.
Chapter 13: Regression Testing Omar Meqdadi SE 3860 Lecture 13 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Software Testing Reference: Software Engineering, Ian Sommerville, 6 th edition, Chapter 20.
Grey Box testing Tor Stålhane. What is Grey Box testing Grey Box testing is testing done with limited knowledge of the internal of the system. Grey Box.
Black Box Testing Techniques Chapter 7. Black Box Testing Techniques Prepared by: Kris C. Calpotura, CoE, MSME, MIT  Introduction Introduction  Equivalence.
Black-box Testing.
Requirements as Usecases Capturing the REQUIREMENT ANALYSIS DESIGN IMPLEMENTATION TEST.
Slide 12A.1 © The McGraw-Hill Companies, 2005 Object-Oriented and Classical Software Engineering Sixth Edition, WCB/McGraw-Hill, 2005 Stephen R. Schach.
The Unified Modeling Language Part II Omar Meqdadi SE 2730 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
System Testing Beyond unit testing. 2 System Testing Of the three levels of testing, system level testing is closest to everyday experience We evaluate.
Software Engineering 2004 Jyrki Nummenmaa 1 BACKGROUND There is no way to generally test programs exhaustively (that is, going through all execution.
Testing OO software. State Based Testing State machine: implementation-independent specification (model) of the dynamic behaviour of the system State:
Software Engineering and Object-Oriented Design Topics: Solutions Modules Key Programming Issues Development Methods Object-Oriented Principles.
Software Engineering1  Verification: The software should conform to its specification  Validation: The software should do what the user really requires.
Winter 2011SEG Chapter 11 Chapter 1 (Part 1) Review from previous courses Subject 1: The Software Development Process.
CS451 Lecture 10: Software Testing Yugi Lee STB #555 (816)
Chapter 24 객체지향 응용프로그램 테스팅 Testing Object-Oriented Applications 임현승 강원대학교 Revised from the slides by Roger S. Pressman and Bruce R. Maxim for the book.
1 Lecture 15: Chapter 19 Testing Object-Oriented Applications Slide Set to accompany Software Engineering: A Practitioner’s Approach, 7/e by Roger S. Pressman.
Software Quality Assurance and Testing Fazal Rehman Shamil.
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
Refining the Use Cases 1. How Use Cases Evolve  Early efforts typically define most of the major use cases.  The refining stages complete the process.
Winter 2007SEG2101 Chapter 121 Chapter 12 Verification and Validation.
1 Using Rational Rose ® to construct UML diagrams.
C++ for Engineers and Scientists, Second Edition 1 Problem Solution and Software Development Software development procedure: method for solving problems.
Testing Overview Software Reliability Techniques Testing Concepts CEN 4010 Class 24 – 11/17.
Software Testing Reference: Software Engineering, Ian Sommerville, 6 th edition, Chapter 20.
Requirement Elicitation Review – Class 8 Functional Requirements Nonfunctional Requirements Software Requirements document Requirements Validation and.
Verification vs. Validation Verification: "Are we building the product right?" The software should conform to its specification.The software should conform.
Defect testing Testing programs to establish the presence of system defects.
CS223: Software Engineering Lecture 25: Software Testing.
Regression Testing with its types
Graph Coverage for Specifications CS 4501 / 6501 Software Testing
Verification and Validation Overview
Applied Software Implementation & Testing
Chapter 24 Testing Object-Oriented Applications
Software testing.
Chapter 19 Testing Object-Oriented Applications
Graph Coverage for Specifications CS 4501 / 6501 Software Testing
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 19 Testing Object-Oriented Applications
Applying Use Cases (Chapters 25,26)
Test Cases, Test Suites and Test Case management systems
Presentation transcript:

Class Testing Software Engineering of Standalone Programs University of Colorado, Boulder

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 2 Overview Class Testing Testing Interactions between objects Testing Class Hierarchies

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 3 Basics – How to test a single class Class Testing How to Test a Class Aspects of Class Testing How to Construct Test Cases When is a class test suite adequate? How to Construct a Test Driver Testing Interactions between objects Testing Class Hierarchies

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 4 Definition of class testing Verifying implementation of a class = verifying the specification for that class If so, each of the instances should behave properly. Assumption: The class in question has a complete and correct specification that has been tested earlier in the context of models Spec is expressed in natural language or as a state transition diagram

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 5 Ways to test a class Code can be tested effectively by inspection (preferable when construction of a test driver is too difficult) execution of test cases (lends itself to easy regression testing later on) Remember: When you test a class, you are really: creating instances of that class and testing the behavior of those instances.

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 6 Aspects of Class Testing Decide test independently test as a component of a larger part of the system How decide – combination of the following: Role of the class in the system – degree of risk Complexity of the class Amount of effort associated with developing a test driver Sometimes, needs so many collaborators, makes more sense to test in a cluster

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 7 Who Tests? How much? Who – class usually tested by its developer Understands class’ spec Familiar with the code Test driver can be used by the developer to debug code while writing it but... perpetuates misunderstanding – needs inspection at model stage to head that off What – ensure that the code for a class exactly meets the requirements – no more, no less

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 8 When are tests written? When – A test plan that identifies test cases should be developed soon after a class is fully specified and ready for coding. Especially if developer is the class tester Why? (What’s the danger in developer alone writing and reviewing test cases for the class?) When again? Iterative development – the driver and the test cases will be available to supplement or change as the class is enhanced or modified

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 9 How can you test “just a class”? How – Create a test driver that creates instances of the class sets up a suitable environment around those instances to run a test case sends one or more messages to an instance as specified by a test case checks the outcome based on a reply value, changes to the instance, or parameters to the message deletes any instances it creates if responsible for storage allocation

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 10 How do we test static data in a class? How – continued: Static data members or operations testing required they belong to the class itself rather than to each instance of the class the class can be treated as an object If the behavior of the instances of a class is based on the values of class-level attributes test cases for testing the class-level attributes must be considered as an extension of the state of the instances

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 11 How MUCH testing is done at this level? How much – Adequacy of testing measured in terms of how much of the specification has been tested how much of the implementation has been tested Want to test operations and state transitions in many combinations Objects maintain state. “State” affects the meaning of operations.

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 12 Constructing test cases - identification Identification of test cases Should be made from the specification that has been reviewed rather than from the implementation which may embody developer’s misunderstandings Best: develop from spec and augment to test boundaries introduced by the implementation If no spec exists: create one from the code and verify it with the developer

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 13 Constructing test cases – identification 2 Identify requirements for test cases for all possible combinations of situations in which a precondition can hold post conditions can be achieved Create test cases for those requirements specific input values – typical and boundary determine correct outputs eliminate conditions that are not meaningful Add test cases to show what happens when a precondition is violated

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 14 Constructing Test Cases – from STD’s State Transition Diagrams They show behavior associated with instances of a class Each transition represents a requirement for one or more test cases

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 15 Constructing test cases from STD’s 2 Suppose 6 transitions between states Plus 1 constructor and 2 destructors That makes 9 requirements Select representative values Select boundary values on each side of a transition If the transition is guarded, select boundary values for the guard condition Boundary values are based on the range of attribute values associated with a state

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 16 Top-level Statechart for Elevator Control

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 17 Adequacy of a Class Test Suite Ideally – exhaustively test each class Practically – impossible or too hard Worth it to exhaustively test some classes with high risk Measures of adequacy to increase confidence that we have tested enough state-based coverage constraint-based coverage Constraints are pre and post conditions and the class invariant code-based coverage

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 18 State-based coverage How many of the transitions in a state transition diagram are covered by the test suite? “Covered” = touched at least once May reveal each transition was covered but test values do not adequately cover value ranges If test cases were generated correctly from a state transition diagram with typical values and good boundary values, the test cases will achieve adequate state-based coverage If test cases were generated from pre- and post conditions, then it is useful to check them against the state transition diagram to ensure each transition is covered.

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 19 State-based coverage: object interaction Note how operations interact w.r.t. transitions Current State Input or event ActionOutputNext State SaE1O1Sc SbE2O2Sc E3Sd Test cases for the transition from Sc to Sd may work if Sc was reached from Sa but not if Sc was reached from Sb. “State” is a function of history.

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 20 State-based coverage: transition pairs Concerning problem on previous page: Check that the test cases cover all pairs of transitions in the state transition diagram. In previous table, create test cases to test: SaSc and ScSd SbSc and ScSd

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 21 Statechart for Elevator Control

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 22 Hierarchical statechart for Elevator Control

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 23 Portion enlarged

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 24 Constraint-based coverage How many pairs of pre- and post conditions have been covered? Using the technique described earlier for generating test cases from pre and post conditions, if one test case is generated to satisfy each requirement, then the test suite meets this measure

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 25 Constraint-Based coverage: object interaction For each operation opn that is not an accessor operation, identify the operations op1, op2, etc. for which their preconditions are met when the post conditions for opn hold. That is, post condition(opn) satisfies (>=) precondition(op1), etc. Then execute test cases for operation sequences opn-op1, opn-op2, etc.

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 26 Class Diagram ElevatorElevator Doors Timer Elevator Button Up Floor Button Floor m 0…n Travels-to Travels-from Opens- Closes Controls Contains velocity: ±m/s position: meters floor: integer on: Boolean open: Boolean closed: Boolean jammed: Boolean time: seconds floor: integer position: meters on: Boolean Down Floor Button 1 1 Contains on: Boolean Light 1 on: Boolean 1 Turns-on Elevator Controller 1 0…n Controls Requests-elevator-of Indicates-arrival-to

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 27 How do we complete the class test? States do not correspond 1-1 to methods or to classes so the state transition diagram gives a different perspective We want to adequately test the class Test each state transition, better yet, the pairs Look at the class diagram and see which classes send messages to it To create a driver to simulate each class sending msgs to the class-under-test could be difficult If you only test each association in this application, it may be a weak level of testing for that class

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 28 Constraint coverage completes testing it If you test class A calling every msg it can in class B, that’s more coverage but … If you use existing classes to do that, it’s hard to get the right combination set up to make it happen Alternative: Write a driver with sequences of messages to access sequences of methods in the class you are testing.

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 29 Which sequences?? Look at the post conditions of each method in the class you want to test Look at preconditions of each Find sequences where the Post(m1) >= pre(m2) the Post(m2) >= pre(m3) Send msgs to m1; m2; m3 Do this for all possible combinations

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 30 Completion check See which associations were tested by comparing to the class diagram See which state transitions were covered this way If some state transitions were missed or if some post/pre condition pairs or associations were missed, add a few tests

November 21, 2005 ECEN5543CSCI5548 Univ of Colorado -- Class Testing 31 Where do the pre and post conditions come from? Use cases?? The methods themselves? The class invariant?