28
Chapter 7 Chapter 7 Unit Testing & Integration Unit Testing & Integration Testing Testing 322 235 Software Testing 322 235 Software Testing By Wararat Songpan(Rungworawut),PH.D. Department of Computer Science, Faculty of Science, Khon Kaen University 1

Chapter 7 Unit Testing & Integration Testing 322 235 Software Testing By Wararat Songpan(Rungworawut),PH.D. Department of Computer Science, Faculty of

Embed Size (px)

Citation preview

Chapter 7Chapter 7 Unit Testing & Integration Unit Testing & Integration

TestingTesting 322 235 Software 322 235 Software

TestingTesting

ByWararat

Songpan(Rungworawut),PH.D.

Department of Computer Science, Faculty of Science, Khon Kaen

University1

Unit TestingUnit Testing

2

Requirements SpecificationRequirements Specification

PreliminaryDesign

PreliminaryDesign

DetailedCoding

DetailedCoding

CodingCoding

Unit TestingUnit Testing

IntegrationTesting

IntegrationTesting

SystemTestingSystemTesting

Acceptance Testing

Unit testingUnit testingUnit Testing is a level of the software testing

process where individual units/components of a software/system are tested. The purpose is to

validate that each unit of the software performs as designed.

A unit is the smallest testable part of software. It usually has one or a few inputs and usually a

single output. In procedural programming a unit may be an individual program, function,

procedure, etc.

3

Unit TestingUnit Testing• Method used for unit testing: Black Box/White

Box Testing method is used for executing the unit test.

• Mostly Unit tests are basically written and executed by software developers to make

sure that code meets its design and requirements and behaves as expected. but not always created by the developers themselves as well, whereas if a company does white box and black box testing,

it can be done by Testers.

4

Unit Testing Unit Testing EnvironmentEnvironment

5

StubStub StubStub StubStub

Test caseTest case

Black Box MethodWhite Box Method

Module is tested

Module is tested

DriverDriver

Actual Results Expected Results

Pass/Fail

Stub ComplexityStub Complexity

6

StubA

StubA

StubB

StubB

StubC

StubC

StubD

StubD

Called Stub A return

Display text

Called Stub B and send

some parameters

Called Stub C only

return parameter

Call Stub Dand both send

and return parameters

Example of Unit Example of Unit TestingTesting

C++o Boost.Testing libraryo CPPUnito CxxUnit

•Javao Junit

•NET Languages (C#, VB.NET, etc.)o Nunit

•Etc.

7

Example of Junit:Example of Junit:

8

Integration TestingIntegration Testing

9

Requirements SpecificationRequirements Specification

PreliminaryDesign

PreliminaryDesign

DetailedCoding

DetailedCoding

CodingCoding

Unit TestingUnit Testing

IntegrationTesting

IntegrationTesting

SystemTestingSystemTesting

Acceptance Testing

Integration TestingIntegration Testing• Integration Testing is a level of the software

testing process where individual units are combined and tested as a group.

10

M1

M2 M3

M5M4 M6 M7

Integration Testing Integration Testing TaskTask

• Integration Test Plano Prepareo Reviewo Reworko Baseline

• Integration Test Cases/Scriptso Prepareo Reviewo Reworko Baseline

• Integration Testo Perform 11

Integration Testing Integration Testing ApproachApproach

• Top Down• Bottom Up• Big Bang• Sandwich/Hybrid

12

Top Down ApproachTop Down Approach• Top Down is an approach to Integration Testing

where top level units are tested first and lower level units are tested step by step after that.

• This approach is taken when top down development approach is followed. Test Stubs are needed to simulate lower level units which may

not be available during the initial phases.• 2 Sub-top downs approach

o Breadth Firsto Depth First

13

Example of Top-down Example of Top-down

14

A

B C D

E

H

F G

I J K

L M

Example of Top-down : Example of Top-down : Breadth FirstBreadth First

• A B C D E F G H I J K L M

15

A

B C D

E

H

F G

I J K

L M

Example of Top-down : Example of Top-down : Depth FirstDepth First

• A B E H C F I D G J L M K

16

A

B C D

E

H

F G

I J K

L M

• Bottom Up is an approach to Integration Testing where bottom level units are tested first and

upper level units step by step after that. • This approach is taken when bottom up

development approach is followed. Test Drivers are needed to simulate higher level units which may not be available during the initial phases.

17

Bottom Up ApproachBottom Up Approach

Bottom-upBottom-up• Build 1: H E B -> create driver for testing• Build 2: I F C D• Build 3: L M J K G

• Integrate all Build 1, 2, 3 Final: A

18

A

B C D

E

H

F G

I J K

L M

Cluster1 Cluster2

Cluster3

• Sandwich/Hybrid is an approach to Integration Testing which is a combination of Top Down and Bottom Up approaches.

19

Sandwich/Hybrid ApproachSandwich/Hybrid Approach

A

B C D

E

H

F G

I J K

L M

• Big Bang is an approach to Integration Testing where all or most of the units are combined

together and tested at one go. This approach is taken when the testing team receives the entire

software in a bundle. • So what is the difference between Big Bang

Integration Testing and System Testing? Well, the former tests only the interactions between the units while the latter tests the entire system.

20

Big Bang ApproachBig Bang Approach

Next Date ProgramNext Date Program

21

Date

Day Month Year

Top downTop down

22

Date

Day Month Year

Unit Under Test

List of Stub

Date Day, Month, Year

Day Month, Year

Month Year

Bottom UpBottom Up

23

Date

Day Month Year

Unit Under Test List of Stub

Year 0

Year+Month 0

Year+Month+Day 0

Year+Month+Day+Date

0

Big BangBig Bang

24

Date

Day Month Year

Unit Under Test List of Stub

Date 0

MM-Path IntegrationMM-Path Integration• Source node is a program statement fragment at

which program execution begins. • Sink node is a statement fragment at which

program execution terminates or ends.• Module Execution Path (MEP) is a sequence of

statements within a module • Message is a programming language mechanism

by which one unit transfers control to another unit• Module to Module path(MM-path) is an interleaved

sequence of module execution paths and messages

25

MM-Path exampleMM-Path example

26

2

1

3 4

5

6

1

2

3

4

1

2 3

4

5

MEP(A, 1) = <1, 2, 3, 6>MEP(A, 2) = <1, 2, 4>MEP(A, 3) = <5, 6>MEP(B, 1) = <1, 2>MEP(B, 2) = <3, 4>MEP (C,1) = <1, 2, 4, 5>MEP (C, 2) = <1, 3, 4, 5>

A B C

A1 A2

A3

B1

B2

C1 C2

MM-Path GraphMM-Path Graph

27

MEP(A,2)MEP(A,1)

Module A

Module B

MEP(B,2)MEP(B,1)

Module C

MEP(C,2)MEP(C,1)

MEP(A,3)

Apply OnlineSystem

Apply OnlineSystem

EnrollmentEnrollmentExam ScheduleExam Schedule

GradingGrading

Graduated StudentGraduated Student

Student ProfileStudent Profile

Quiz Integration TestingQuiz Integration Testing