Test Driven Development Large Scale

Post on 24-Apr-2015

29 views 3 download

Transcript of Test Driven Development Large Scale

Test-Driven Development

on a

Large Scale Project

SpeakerJan Van Reusel

Speaker1997

Jan Van Reusel

Speaker1997 1999

Jan Van Reusel

Speaker1997 1999 2002

Jan Van Reusel

Speaker1997 1999 2002 2003 2003

Jan Van Reusel

SpeakerDevelopment Manager

SpeakerWhat keeps me awake

at night?

...sometimes...

...more often...

...summer 2005...

Load factor

0

2

4

6

8

10

12

05/05 07/05 09/05 11/05 01/06 03/06 05/06 07/06 09/06

...summer 2006...

This SessionWhat did we do about it?

ContextVentouris Renewal Program

Accountancy

Bailiff

Bank

Payments

• receive

• reassign

• reimburse

• Self-employed activity

• Look up and process income data

• Career data

• Continued insurance

Calculation

Family allowance

FCP

Self-employed

NISSE

• Discharge

• Pension

• Decease

• Failure (insurance)

• Normal suspension: request

• equalization

• continued insurance

Suspension

Request remission /

exemptionDebt administration

• Reminder

• Summons

• Subpoena

Affiliation

File

Modifications

608

3 year

100 my

customers team size

Application clients

Application Infrastructure

Presentation Layer

Service Layer

Domain Layer

Data Source Layer

<<Oracle>>

DatabaseFile System

HTML Browser Batch ClientWeb Service Client NISSE

<<JCAPS>>

BPEL Engine

<<POJO / MDB>>

NISSE Gateway

<<POJO / MDB>>

Batch Dispatcher

<<Session Bean>>

Application Services

<<POJO>>

Business Object

<<POJO / MDB>>

File Gateway

<<JDO>>

Domain Store

<<JESS>>

Rule Engine

<<POJO>>

Document Gateway

<<Scriptura>>

Document Generator

<<JSF>>

Web User Interface

Why TDD?

Design

Documentation

Scope

Trust

Unit

Integration (Java)

Exploratory (proxy) Integration (XML)

Exploratory (customer)

System

Alfa

Beta

Data conversion

Performance

Fail over

Business Facing

Technology Facing

Support Programming

Critique Product

Brian Marick

Test Strategy

Developer 1 Machine Database Server

Build/Test Process Application Server

Database

Schema 1

Schema 2

Schema 3

Developer 2 Machine

Build/Test Process Application Server

Developer 3 Machine

Build/Test Process Application Server

Client Presentation DomainService Infrastructure

RDBMS

JSF

Component

Faces

Servlet

Session

Facade

Persistence

Manager

Facade

Impl

Data Source

Business

Object

Business

Object

JDO

Browser

Managed

Bean

Gateway

Client Presentation DomainService Infrastructure

RDBMS

JSF

Component

Faces

Servlet

Session

Facade

Persistence

Manager

Facade

Impl

Data Source

Business

Object

Business

Object

JDO

Browser

Managed

Bean

Gateway

http://xunitpatterns.com

Replace code on which SUT depends

http://xunitpatterns.com

http://xunitpatterns.com

http://xunitpatterns.com

Control indirect input

http://xunitpatterns.com

Verify indirect output

Client Presentation DomainService Infrastructure

RDBMS

JSF

Component

Faces

Servlet

Session

Facade

Persistence

Manager

Facade

Impl

Data Source

Business

Object

Business

Object

JDO

Browser

Managed

Bean

Gateway

Mock Object or Test Stub

Client Presentation DomainService Infrastructure

RDBMS

JSF

Component

Faces

Servlet

Session

Facade

Persistence

Manager

Facade

Impl

Data Source

Business

Object

Business

Object

JDO

Browser

Managed

Bean

Gateway

Client Presentation DomainService Infrastructure

RDBMS

JSF

Component

Faces

Servlet

Session

Facade

Persistence

Manager

Facade

Impl

Data Source

Business

Object

Business

Object

JDO

Browser

Managed

Bean

Gateway

Test

Helper

http://xunitpatterns.com

http://www.thoughtworks.com/object-mother-easing-test-object-creation.pdf

Object Mother

Client Presentation DomainService Infrastructure

RDBMS

JSF

Component

Faces

Servlet

Session

Facade

Persistence

Manager

Facade

Impl

Data Source

Business

Object

Business

Object

JDO

Browser

Managed

Bean

Gateway

Test

Helper

Object Mother

Mock Object Mock Object or Test Stub

Humble Object

Client Presentation DomainService Infrastructure

RDBMS

JSF

Component

Faces

Servlet

Session

Facade

Persistence

Manager

Facade

Impl

Data Source

Business

Object

Business

Object

JDO

Browser

Managed

Bean

Gateway

Client Presentation DomainService Infrastructure

RDBMS

JSF

Component

Faces

Servlet

Session

Facade

Persistence

Manager

Facade

Impl

Data Source

Business

Object

Business

Object

JDO

Browser

Managed

Bean

Gateway

Client Presentation DomainService Infrastructure

RDBMS

JSF

Component

Faces

Servlet

Session

Facade

Persistence

Manager

Facade

Impl

Data Source

Business

Object

Business

Object

JDO

Browser

Managed

Bean

Gateway

http://www.openqa.org/selenium

JUnit Test Process

Selenium Driver

Selenium Server

Selenese Proxy WebApp

Web Server

AUT WebApp

Browser Process

AUT

Selenium Browser Bot

http://www.openqa.org/selenium

JUnit Test Process

Selenium Driver

Selenium Server

Selenese Proxy WebApp

Web Server

AUT WebApp

Browser Process

AUT

Selenium Browser Bot1. Launches

http://www.openqa.org/selenium

JUnit Test Process

Selenium Driver

Selenium Server

Selenese Proxy WebApp

Web Server

AUT WebApp

Browser Process

AUT

Selenium Browser Bot1. Launches

2. Requests command

http://www.openqa.org/selenium

JUnit Test Process

Selenium Driver

Selenium Server

Selenese Proxy WebApp

Web Server

AUT WebApp

Browser Process

AUT

Selenium Browser Bot1. Launches

2. Requests command

3. Waits

http://www.openqa.org/selenium

JUnit Test Process

Selenium Driver

Selenium Server

Selenese Proxy WebApp

Web Server

AUT WebApp

Browser Process

AUT

Selenium Browser Bot1. Launches

2. Requests command

4. “Go to AUT” & request result

3. Waits

http://www.openqa.org/selenium

JUnit Test Process

Selenium Driver

Selenium Server

Selenese Proxy WebApp

Web Server

AUT WebApp

Browser Process

AUT

Selenium Browser Bot1. Launches

2. Requests command

4. “Go to AUT” & request result

3. Waits

http://www.openqa.org/selenium

JUnit Test Process

Selenium Driver

Selenium Server

Selenese Proxy WebApp

Web Server

AUT WebApp

Browser Process

AUT

Selenium Browser Bot1. Launches

2. Requests command

4. “Go to AUT” & request result

5. “Go to AUT”

3. Waits

http://www.openqa.org/selenium

JUnit Test Process

Selenium Driver

Selenium Server

Selenese Proxy WebApp

Web Server

AUT WebApp

Browser Process

AUT

Selenium Browser Bot1. Launches

2. Requests command

4. “Go to AUT” & request result

5. “Go to AUT”

6. “Go to AUT”

3. Waits

http://www.openqa.org/selenium

JUnit Test Process

Selenium Driver

Selenium Server

Selenese Proxy WebApp

Web Server

AUT WebApp

Browser Process

AUT

Selenium Browser Bot1. Launches

2. Requests command

4. “Go to AUT” & request result

5. “Go to AUT” 7. HTTP Request

6. “Go to AUT”

3. Waits

http://www.openqa.org/selenium

JUnit Test Process

Selenium Driver

Selenium Server

Selenese Proxy WebApp

Web Server

AUT WebApp

Browser Process

AUT

Selenium Browser Bot1. Launches

2. Requests command

4. “Go to AUT” & request result

5. “Go to AUT” 7. HTTP Request 8. HTTP Response

6. “Go to AUT”

3. Waits

http://www.openqa.org/selenium

JUnit Test Process

Selenium Driver

Selenium Server

Selenese Proxy WebApp

Web Server

AUT WebApp

Browser Process

AUT

Selenium Browser Bot1. Launches

2. Requests command

4. “Go to AUT” & request result

5. “Go to AUT” 7. HTTP Request 8. HTTP Response

6. “Go to AUT” 9. Gets result

3. Waits

http://www.openqa.org/selenium

JUnit Test Process

Selenium Driver

Selenium Server

Selenese Proxy WebApp

Web Server

AUT WebApp

Browser Process

AUT

Selenium Browser Bot1. Launches

2. Requests command

4. “Go to AUT” & request result

5. “Go to AUT” 7. HTTP Request 8. HTTP Response

10. Returns result &

requests command

6. “Go to AUT” 9. Gets result

3. Waits

http://www.openqa.org/selenium

JUnit Test Process

Selenium Driver

Selenium Server

Selenese Proxy WebApp

Web Server

AUT WebApp

Browser Process

AUT

Selenium Browser Bot1. Launches

2. Requests command

4. “Go to AUT” & request result

5. “Go to AUT” 7. HTTP Request 8. HTTP Response

10. Returns result &

requests command

6. “Go to AUT” 9. Gets result

3. Waits

11. Waits

http://www.openqa.org/selenium

JUnit Test Process

Selenium Driver

Selenium Server

Selenese Proxy WebApp

Web Server

AUT WebApp

Browser Process

AUT

Selenium Browser Bot1. Launches

2. Requests command

4. “Go to AUT” & request result

5. “Go to AUT” 7. HTTP Request 8. HTTP Response

10. Returns result &

requests command

6. “Go to AUT” 9. Gets result12. Result

3. Waits

11. Waits

http://www.openqa.org/selenium

JUnit Test Process

Selenium Driver

Selenium Server

Selenese Proxy WebApp

Web Server

AUT WebApp

Browser Process

AUT

Selenium Browser Bot1. Launches

2. Requests command

4. “Go to AUT” & request result

5. “Go to AUT” 7. HTTP Request 8. HTTP Response

10. Returns result &

requests command

6. “Go to AUT” 9. Gets result12. Result

13. Asserts on result

3. Waits

11. Waits

import com.thoughtworks.selenium.*;

import junit.framework.*;

public class GoogleTest extends TestCase {

private Selenium sel;

public void setUp() {

sel = new DefaultSelenium("localhost",

4444, "*firefox", "http://www.google.com");

sel.start();

}

public void testGoogle() {

sel.open("http://www.google.com/webhp");

sel.type("q", "hello world");

sel.click("btnG");

sel.waitForPageToLoad("5000");

assertEquals("hello world - Google Search", sel.getTitle());

}

public void tearDown() {

sel.stop();

}

}

Test Smells

Load factor

0

2

4

6

8

10

12

05/05 07/05 09/05 11/05 01/06 03/06 05/06 07/06 09/06

Buggy Tests

Buggy Tests

Load factor

0

2

4

6

8

10

12

05/05 07/05 09/05 11/05 01/06 03/06 05/06 07/06 09/06

High Test Maintenance Cost

High Test Maintenance Cost

High Test Maintenance Cost

High Test Maintenance Cost

http://xunitpatterns.com

High Test Maintenance Cost

Client Presentation DomainService Infrastructure

RDBMS

JSF

Component

Faces

Servlet

Session

Facade

Persistence

Manager

Facade

Impl

Data Source

Business

Object

Business

Object

JDO

Browser

Managed

Bean

Gateway

Mock Object

Mock Object

High Test Maintenance Cost

High Test Maintenance Cost

High Test Maintenance Cost

High Test Maintenance Cost

High Test Maintenance Cost

Load factor

0

2

4

6

8

10

12

05/05 07/05 09/05 11/05 01/06 03/06 05/06 07/06 09/06

Slow Tests

Slow Tests

Slow Tests

Slow Tests

Client Presentation DomainService Infrastructure

RDBMS

JSF

Component

Faces

Servlet

Session

Facade

Persistence

Manager

Facade

Impl

Data Source

Business

Object

Business

Object

JDO

Browser

Managed

Bean

Gateway

Mock Object

Slow Tests

Slow Tests

Slow Tests

!2HRSbuild

time

test

maintenance

Not Enough

Not EnoughLost ability to

respond to change

Not EnoughToo many tests

too much overlap

Not EnoughSlow component usage

Client Presentation DomainService Infrastructure

RDBMS

JSF

Component

Faces

Servlet

Session

Facade

Persistence

Manager

Facade

Impl

Data Source

Business

Object

Business

Object

JDO

Browser

Managed

Bean

Gateway

Not EnoughTest type number % time %

predeploy 5020 66 170 3

postdeploy 2606 34 5072 97

Not EnoughTest type number % time %

predeploy 5020 66 170 3

postdeploy 2606 34 5072 97

Reduce to smoke tests

Result!10 minute build

Client Presentation DomainService Infrastructure

RDBMS

JSF

Component

Faces

Servlet

Session

Facade

Persistence

Manager

Facade

Impl

Data Source

Business

Object

Business

Object

JDO

Browser

Managed

Bean

Gateway

Conclusion

Continuous design

Educate your team

Be agile with test strategy

Tests as we

ll!

Tests as we

ll!

Tests as we

ll!

Tests as we

ll!

More?

Agile Applied on The Largest J2EE Project in The Beneluxby

Johan Lybaert

Agile Development Workshopby

Kathleen Cornelis

www.ardatissoftwarefactory.com