cairo university faculty of computers and information cs251 – software engineering lecture 20: sw...

55
Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD http://www.acadox.com/join/75UDWT

Upload: dale-grant-garrett

Post on 29-Jan-2016

224 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

Cairo UniversityFaculty of Computers and Information

CS251 – Software Engineering

Lecture 20: SW Testing

Presented by:

Mohammad El-Ramly, PhD

http://www.acadox.com/join/75UDWT

Page 2: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

2

Outline

Definition of Software Testing Testing as a Quality Assurance Technique Testing Terminology Levels and Types of Testing

Page 3: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

3

Page 4: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

4

What is a computer program?

Page 5: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

5

What is a house?

Page 6: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

6

Any better definition?

The focus is on•Stakeholders

– (for people)•Purpose

– (to live in)

Stakeholder:Any person affected by:•success or failure of a project, or •actions or inactions of a product, or•effects of a service.

Page 7: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

7

Apply this definition to prog.

Page 8: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

8

Apply this definition to prog.

A computer program is• a communication• among several humans and

computers• who are distributed over space

and time,• that contains instructions that

can be executed by a computer.

Page 9: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

9

Software Quality

Page 10: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

10

Software Error (Bug)

Page 11: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

11

Software Error (Bug)

An attribute of a software product that reduces its value to a favored

stakeholder or increases its value to a disfavored

stakeholderwithout a sufficiently large countervailing

benefit.

An error may or may not be a coding error, or a functional error. Design errors are bugs too.

Page 12: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

12

Software Testing

• is an empirical• technical • investigation• conducted to provide stakeholders• with information • about the quality• of the product or service under test

Page 13: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

13

Software Testing

Page 14: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

14

Software Testing is Search for Information

1. Find important bugs

2. Assess the quality of the product

3. Help managers assess the progress of the

project

4. Help managers make release decisions

5. Block premature product releases

6. Help predict and control product support costs

7. Check interoperability with other products

Page 15: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

15

Software Testing is Search for Information

8. Assess conformance to specifications

9. Certify the product meets a particular

standard

10.Ensure the testing process meets

accountability standards

11.Minimize the risk of safety-related lawsuits

12.Help clients improve their processes

13.Evaluate the product for a third party

Page 16: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

16

Fact of testing

Testing does not guarantee

the absence of defects

it gurantees their presence

Page 17: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

17

Page 18: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

18

Assume we want to test Font Increase functionality in Word

CalibriFont size

from 7 to 13.5

Page 19: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

19

Assume we want to test Font Increase functionality in Word

ArialFont size

from 7 to 13.5

Page 20: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

20

Assume we want to test Font Increase functionality in Word

Times New Roman

Font size from 7 to 13.5

Page 21: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

21

Assume we want to test Font Increase functionality in Word

Courier NewFont size from 7 to 13.5

Page 22: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

22

Page 23: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

23

So, what should we test?

Page 24: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

24

So, what should we test?

What to cover? Every font size (to a tenth of a point). Every character in every font. Every method of changing font size. Every user interface element associated with font size

functions. Interactions between font sizes and other contents of a

document. Interactions between font sizes and every other feature

in Word. Interactions between font sizes and graphics cards &

modes. Print vs. screen display.

Page 25: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

A program can fail in many ways

System under

test

Program state

Intended inputs

System state

Configuration andsystem resources

From other cooperating processes, clients or servers

Monitored outputs

Program state, including uninspected outputs

System state

Impacts on connected devices / system resources

To other cooperating processes, clients or servers

Page 26: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

Unit testing with JUnit 26

Page 27: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

27

Page 28: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

28

Why?

Why testing? Improve software quality Increase customer satisfaction and reduce cost Finish faster and on budget Catch errors and bugs

In short, to Produce Better Code

Page 29: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

29

What should be tested ?

Test for boundary conditions Test for both success and failure Test for general functionality Test for configuration and resources Test for interoperability Etc..

Page 30: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

30

When to start testing

Software quality and is a life-cycle process

Testing can start as early as

the project starts

Page 31: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

Software Quality

Landscape

Plannin

g

Requir

emen

ts

Design

Develo

pmen

t

Testin

g

Guidelines,

Standards a

nd

Templates

QA Planning

and Budgetin

g

Testing

Debugging

Reviews

Refactorin

g

Requirements

V & V

Design R

eview

Collabora

tive

Development /

Reviews

Metrics

Change and Configuration Management

Bug Tracking Surveys

Deploy

ment &

Mainten

ance

M a n a g e m e n t

Contract

Review

Page 32: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

Software Quality

Landscape

Plannin

g

Requir

emen

ts

Design

Develo

pmen

t

Testin

g

Guidelines,

Standards a

nd

Templates

QA Plannin

g

and Budgetin

g

Testing

Debugging

Reviews

Refactorin

g

Requirements

V & V

Design R

eview

Collabora

tive

Development /

Reviews

Metrics

Change and Configuration Management

Bug Tracking Surveys

Deploy

ment &

Mainten

ance

M a n a g e m e n t

Contract

Review

Page 33: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

Software Quality

Landscape

Plannin

g

Require

men

ts

Desig

n

Develo

pmen

t

Testin

g

Guidelines,

Standards a

nd

Templates

QA Plannin

g

and Budgetin

g

Testing

Debugging

Reviews

Refactorin

g

Requirements

V & V

Design R

eview

Collabora

tive

Development /

Reviews

Metrics

Change and Configuration Management

Bug Tracking Surveys

Deploy

ment &

Mainten

ance

M a n a g e m e n t

Contract

Review

Page 34: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

04/22/23 CPSC-4360-01, CPSC-5360-01, Lecture 11

34

Testing Organization (V-Model)

Produce ValidateRequirements specification

System Specification

System Design

Module Design

Coding

UnitTesting

IntegrationTesting

System Testing

Acceptance Testing

UserSpecification

SystemSpecification

SoftwareSpecification

ModuleSpecification

Produce Validate

Produce Validate

Produce Validate

Page 35: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

Testing Terminology

Page 36: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

What is test case

36

A test case is a document that describes an input, action, or event and an expected response, to determine if a feature of an application is working correctly

1

Page 37: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

37

Good test case design

An good test case satisfies the following criteria: Reasonable probability of catching an error Does interesting things Doesn’t do unnecessary things Neither too simple nor too complex Not redundant with other tests Makes failures obvious Mutually Exclusive, Collectively Exhaustive

Page 38: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

Unit testing with JUnit 38

Test case design technique

Test case design techniques can be broadly split into two main categories

Black box (functional)

White box (structural)

2

3

Page 39: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

39

Black Box tests

Targeted at the apparent simplicity of the software Makes no assumptions about implementation Good for testing component interactions

Tests the interfaces and behavior

Input Output

2

Page 40: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

40

White Box tests

Targeted at the underlying complexity of the software Intimate knowledge of implementation Good for testing individual functions

Tests the implementation and design

Input Output

3

Page 41: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

Black box testing: Test against the specifications of the component Tests the interface of the component.

White box testing: Test design and implementation of the

component. Test cases exercise specific sets of condition,

loops, etc.

Black box vs. White box

Page 42: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

CPSC-4360-01, CPSC-5360-01, Lecture 11

Test to specifications: Also known as black-box, data-driven, functional, or input/output

driven testing. Ignore the code — use the specifications to select test cases.

Test to code: Also known as glass-box, logic-driven, structured, or path-

oriented testing. Ignore the specifications — use the code to select test cases.

Neither exhaustive testing to specifications nor exhaustive testing to code is feasible.

Another way to classifytest cases

Page 43: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

43

Page 44: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

Unit testing with JUnit 44

Test case writing example

Suppose we have two parameters we want to cover in a set of tests. Parameters are as follows..

Operating system Win98 Win2k Winxp

Printers HP 4100 HP 4200

How We should write test case for this ??

Page 45: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

Unit testing with JUnit 45

Types (Levels) of Tests

Unit Testing Individual classes or types

Component Testing Group of related classes or

types

Integration Testing Interaction between classes

4

5

6

Page 46: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

46

Types (Levels) of Tests

System Testing Testing to confirm that all code

modules work as specified, and that the system as a whole performs adequately on the platform on which it will be deployed.

Acceptance Testing Final testing usually involving

users to ensure their requirements are met.

7

8

Page 47: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

Testing that Involves Users Alpha testing:

In-house testing. By a test team or end users.

Beta testing: By users or selected subset of actual customers in a normal

work environment. Product is very close to completion. Open beta release: Let public carry out the beta testing.

Acceptance testing: By users to check that system satisfies requirements to

decide whether to accept the system based on the test result.

9

10

Page 48: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

48

Page 49: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

49

What is a testing framework?

A test framework provides reusable test functionality which: Is easier to use (e.g. don’t have to write the same

code for each class) Is standardized and reusable Provides a base for regression tests

11

Page 50: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

Regression testing

New code and changes to old code can affect the rest of the code base ‘Affect’ sometimes means ‘break’

We need to run tests on the old code, to verify it works – these are regression tests

Regression testing is required for a stable, maintainable code base

12

Page 51: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

51

Why use a testing framework?

Each class must be tested when it is developed

Each class needs a regression test Regression tests need to have standard

interfaces Thus, we can build the regression test when

building the class and have a better, more stable product for less work

Page 52: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

52

Example: Old way vs. new way int max(int a, int b) {

if (a > b) { return a; } else { return b; }}

void testMax() { int x = max(3, 7); if (x != 7) { System.out.println("max(3, 7) gives " + x); } x = max(3, -7); if (x != 3) { System.out.println("max(3, -7) gives " + x); }}

public static void main(String[] args) { new MyClass().testMax();}

@Testvoid testMax() { assertEquals(7, max(3, 7)); assertEquals(3, max(3, -7));}

Page 53: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

53

JUnit

JUnit is a framework for writing unit tests A unit test is a test of a single class

A test case is a single test of a single method A test suite is a collection of test cases

Unit testing is particularly important when software requirements change frequently Code often has to be refactored to incorporate the

changes Unit testing helps ensure that the refactored code

continues to work

13

14

Page 54: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

54

JUnit..

JUnit helps the programmer: Define and execute tests and test suites Formalize requirements and clarify architecture Write and debug code Integrate code and always be ready to release a

working version

Page 55: Cairo University Faculty of Computers and Information CS251 – Software Engineering Lecture 20: SW Testing Presented by: Mohammad El-Ramly, PhD

55

Test suites Obviously you have to test your code to get it working in

the first place You can do ad hoc testing (testing when something happens), or You can build a test suite (set of tests that can be run at any time)

Disadvantages of writing a test suite It’s a lot of extra programming

True—but use of a good test framework can help quite a bit You don’t have time to do all that extra work

False—Experiments repeatedly show that test suites reduce debugging time more than the amount spent building the test suite

Advantages of having a test suite Your program will have many fewer bugs It will be a lot easier to maintain and modify your program