modern methods in software engineering testing - …misha/id2207/2014/lectures/... ·  ·...

46
Modern Methods in Software Engineering Testing www.imit.kth.se/courses/2G1522

Upload: vuongdieu

Post on 19-Apr-2018

223 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Modern Methods in

Software Engineering

Testing

www.imit.kth.se/courses/2G1522

Page 2: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Literature used

• Text book

Chapter 11

Page 3: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Introduction Content

• Terminology

• Types of errors

• Dealing with errors

• Component Testing

– Unit testing

– Integration testing

• System testing

– Function testing

– Structure Testing

– Performance testing

– Acceptance testing

– Installation testing

• Summary

Page 4: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

What is testing?

• Testing is the process of analyzing a system or

components to detect the differences between

specified (required) and observed (existing)

behavior

• Systematic way to find faults in a planned way

in the implemented software

Page 5: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Testing

• Testing often viewed as dirty work (that is completely wrong!)

• To develop an effective test, one must have:

• Detailed understanding of the system

• Knowledge of the testing techniques

• Skill to apply these techniques in an effective and efficient manner

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 6: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Testing

• Testing is done best by independent testers

• Programmer often stick to the data set that makes the program work – "Don’t mess up my code!"

• A program often does not work when tried by somebody else – Don't let this be the end-user.

Page 7: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Overview • Reliability: The measure of success with which the

observed behavior of a system confirms to some specification of its behavior.

• Fault (Bug): The mechanical or algorithmic cause of an error (a design or coding mistake that may cause abnormal component behavior)

• Erroneous state (Error): manifestation of the fault during the execution of the system. The system is in a state such that further processing by the system can lead to a failure

• Failure: Any deviation of the observed behavior from the specified behavior.

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 8: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Overview

• test case: a set of inputs and expected results that exercises a component with the purpose of causing failures and detecting faults.

• test stub: a partial implementation of components on which the tested component depends.

• test driver: a partial implementation of a component that depends on the tested component

Page 9: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

What is this?

A failure?

An error?

A fault?

Need to specify

the desired behavior first!

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 10: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Erroneous State (“Error”)

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 11: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Faults and Erroneous States (Errors)

• Faults in the Interface specification

• Algorithmic Faults

• Mechanical Faults (very hard to find)

Page 12: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Algorithmic Fault

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 13: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Mechanical Fault

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 14: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

How to Deal with Errors

• Error prevention (before the system is released):

– Use good programming methodology to reduce complexity

– Use version control to prevent inconsistent system

– Apply verification to prevent algorithmic bugs

Page 15: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

How do we deal with Errors and Faults?

Verification

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 16: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

How do we deal with Errors and Faults?

• Error detection

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 17: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

How do we deal with Errors and Faults?

• Error detection (while system is running):

– Testing: Create failures in a planned way

– Debugging: Start with an unplanned failures

– Monitoring: Deliver information about state.

Find performance bugs

Page 18: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Fault tolerance

• Assumes that the system can be released

with faults and that system failures can be

dealt with by recovering from them in

runtime

Page 19: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

How do we deal with Errors and Faults?

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Modular Redundancy?

Page 20: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

How do we deal with Errors and Faults?

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Declaring a bug to be a “feature”

Page 21: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

How do we deal with Errors and Faults?

• Error recovery (recover from failure once

the system is released):

– Data base systems (atomic transactions)

– Recovery blocks

Page 22: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

How do we deal with Errors and Faults?

Patching?

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 23: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Testing Activities Diagram

Functional test

Structure test

User Client Developer

Integration test Integration

strategy

From TP

System

decomposition

From SDD

Functional

requirements

From RAD

Continued

on next slide

Object design Unit test

From ODD

Management

plan

Test planning

User interface

design

Usability test

From RAD

Continued

on next slide

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 24: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Testing activities Diagram (cntd.)

Acceptance test

User manual

Performance test

Daily operation

Functional test

Installation test

Field test

User Client Developer

From RAD

Functional

requirements

From RAD

Nonfunctional

requirements

Project

agreement

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 25: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Usability testing

• Scenario test

• Prototype test

• Product test

Page 26: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Unit Testing elements • Static Analysis:

– Hand execution: Reading the source code

– Automated Tools checking for

• syntactic and semantic errors

• departure from coding standards

• Dynamic Analysis:

– Black-box testing (Test the input/output behavior)

– White-box testing (Test the internal logic of the

subsystem or object)

Page 27: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Black-box Testing

• Focus: I/O behavior.

• Goal: Reduce number of test cases by equivalence partitioning:

– Divide input conditions into equivalence classes

– Choose test cases for each equivalence class.

• Selection of equivalence classes (No rules, only guidelines):

– Input is valid across range of values. Select test cases from 3 equivalence classes:

• Below the range

• Within the range

• Above the range

– Input is valid if it is from a discrete set. Select test cases from 2 equivalence classes:

• Valid discrete value

• Invalid discrete value

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 28: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

A (faulty) implementation of the getNumDaysInMonth() method public class MonthOutOfBounds extends Exception {…};

public class YearOutOfBounds extends Exception {…};

public class MyGregorianCalendar {

public static boolean isLeapYear(int year) {

boolean leap;

if (year%4) {

leap = true;

} else {

leap = false;

}

return leap;

}

public static int getNumDaysInMonth(int month, int year) throws MonthOutOfBounds, YearOutOfBounds {

int numDays;

if (year < 1) {

throw new YearOutOfBounds(year);

}

if (month==1||month==3||month==5||month==7||month==10||month==12) {

numDays = 32;

} else if (month == 4 || month == 6 || month == 9 || month == 11) {

numDays = 30;

} else if (month == 2) {

if (isLeapYear(year)) {

numDays = 29;

} else {

numDays = 28;

}

} else {

throw new MonthOutOfBounds(month);

}

return numDays;

}... Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 29: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Equivalence classes and selected valid

inputs

Equivalence class Month input Year input

31 days, non-leap year July 1901

31 days, leap year July 1904

30 days, non-leap year June 1901

30 days, leap year June 1904

28 or 29 days, non-leap year February 1901

28 or 29 days, leap year February 1904

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 30: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Boundary testing

Equivalence class Month input Year input

Leap years divisible by 400 February 2000

Non-Leap years divisible by 100 February 1900

Nonpositive invalid months 0 1234

Positive invalid months 13 1831

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 31: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

White-box Testing

• Focus: Thoroughness (Coverage). Every statement

in the component is executed at least once.

• Statement Testing (Algebraic Testing): Test

single statements

• Loop Testing:

– Cause execution of the loop to be skipped completely.

(Exception: Repeat loops)

– Cause execution of the loop to be executed exactly once

– Cause execution of the loop to be executed more than

once

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 32: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

White-box Testing

• Branch Testing (Conditional Testing): Make sure that each possible outcome from a condition is tested at least once

• Path testing:

– Make sure all paths in the program are executed

if ( i = TRUE) printf("YES\n"); else printf("NO\n"); Test cases: 1) i = TRUE; 2) i = FALSE

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 33: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Equivalent flow graph for the

getNumDaysInMonth() method implementation

[year < 1]

[month in (1,3,5,7,10,12)]

n=32

throw2 n=29

return

throw1

n=28

n=30

[month in (4,6,9,11)]

[month == 2] [leap(year)]

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 34: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Path testing

Test case Path

(year=0, month=1) {throw1}

(year=1901, month=1) {n=32 return}

(year=1901, month=2) {n=28 return}

(year=1904, month=2) {n=29 return}

(year=1901, month=4) {n=30 return}

(year=1901, month=0) {throw2}

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 35: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Integration testing strategies

User Interface (A)

Billing (B) Event Service (C) Learning (D)

Database (E) Network (F) Neural Network (G)

Layer III

Layer II

Layer I

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 36: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Integration testing strategies (bottom-up)

Database (E) Network (F) Neural Network (G)

User Interface (A)

Billing (B) Learning (D)

T riple test B,E,F

Event Service (C)

Double test D,G

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 37: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Integration testing strategies (top-down)

Database (E) Network (F) Neural Network (G)

User Interface (A)

Billing (B) Learning (D)

Double tests A,B; A,C; A,D

Event Service (C)

Quad test

A,B,C,D

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 38: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Integration testing strategies (sandwich)

Test A

Test G

Test B,E,F

Test D,G

Test A,D

Test A,B

Test A,C Test A,B,C,D

E,F,G

Test A,B,C,D,

Test E

Test F

Top layer

Bottom layer

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 39: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Integration testing strategies (sandwich)

Test A

Test G

Test B,E,F

Test D,G

Test A,D

Test A,B

Test A,C Test A,B,C,D

E,F,G

Test A,B,C,D,

Test E

Test F

Test B

Test C

Test D

Top layer

Target layer

Bottom layer

Adopted from Bernd Bruegge & Allen H. Dutoit Object-Oriented Software Engineering: Using UML, Patterns, and Java

Page 40: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

System Testing

• Functional testing

• Performance testing

• Acceptance testing

• Pilot testing

• Installation testing

Page 41: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Functional testing

• Finds differences between the functional

requirements and the system

• BlackBox technique

• Test cases are derived from use case model

• Selects tests that are relevant to the user and

have high probability of a failure

Page 42: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Performance testing

• Stress testing

• Volume testing

• Security testing

• Timing testing

• Recovery tests

Page 43: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Acceptance testing

• Benchmark test

• Competitor testing

• Shadow testing

Page 44: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Pilot testing (field test)

• The system is installed and used by a selected set of users

• Pilot tests are useful when a system is built without a specific set of requirements or without a specific customer in mind

• An alpha test is a pilot test with users exercising the system in the development environment

• In a beta test, the acceptance test is performed by a limited number of end users in the target environment

Page 45: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Installation testing

• Testing reconfiguration

• Often repeats test cases from previous phases

• Some requirements cannot be executed in

the development environment because they

require target-specific resources

Page 46: Modern Methods in Software Engineering Testing - …misha/ID2207/2014/lectures/... ·  · 2014-10-01Modern Methods in Software Engineering Testing ... Adopted from Bernd Bruegge

Chapters in the text-book that are

less relevant to the exam

• Chapter 3 – Project organization and

Communication

• Chapter 12 – Rational Management

• Chapter 13 – Configuration Management

• Chapter 14 – Project Management