Transcript
Page 1: Pragmatic Test Driven Development

PragmaticTest Driven Development

Sunday, January 22, 12

Page 2: Pragmatic Test Driven Development

Your Host

ClaytonLengel-Zigich

[email protected]

Certified Scrum MasterCertified Scrum Product OwnerCertified Scrum Professional

@claytonlz

Sunday, January 22, 12

Page 3: Pragmatic Test Driven Development

Types of Testing

Sunday, January 22, 12

Page 4: Pragmatic Test Driven Development

Types of Testing

Acceptance

Integration

Unit

Sunday, January 22, 12

Page 5: Pragmatic Test Driven Development

Types of Testing

POÄNG

This piece should be 24”

These third-party rubber feetshould fit

Given all of these pieces,I can sit in the chair

Sunday, January 22, 12

Page 6: Pragmatic Test Driven Development

Types of Testing

Acceptance

Unit Unit UnitUnit Unit Unit

Acceptance

Sunday, January 22, 12

Page 7: Pragmatic Test Driven Development

Types of TestingFeature

Unit Unit Unit

Acceptance

Feature

Unit Unit Unit

Acceptance

Feature

Unit Unit Unit

Acceptance

Feature

Unit Unit Unit

Acceptance

Feature

Unit Unit Unit

Acceptance

Feature

Unit Unit Unit

Acceptance

Sunday, January 22, 12

Page 8: Pragmatic Test Driven Development

Who’s Responsible?

Sunday, January 22, 12

Page 9: Pragmatic Test Driven Development

Who’s Responsible?

QA

QA QA QA QA QA QA QA

QA QA QA QA QA QA QA

QA QA QA QA QA QA QA

QA QA QA QA QA QA QA

QA QA QA QA QA QA QA

QA QA QA QA QA QA QA

Sunday, January 22, 12

Page 10: Pragmatic Test Driven Development

Who’s Responsible?

QA

Sunday, January 22, 12

Page 11: Pragmatic Test Driven Development

Who Writes Unit Tests?

Sunday, January 22, 12

Page 12: Pragmatic Test Driven Development

Who Writes Acceptance Tests?

DEV

CUSTOMER

QA

Discovery

Sunday, January 22, 12

Page 13: Pragmatic Test Driven Development

Automated Testing

Sunday, January 22, 12

Page 14: Pragmatic Test Driven Development

Continuous Integration

Continuous integration avoids or detects compatibility problems early ... if you integrate throughout the project in small amounts you will not find your self trying to integrate the system for weeks at the project's end while the deadline slips by.

Always work in the context of the latest version of the system.

Sunday, January 22, 12

Page 15: Pragmatic Test Driven Development

Continuous Integration

BuildServer

SCM

SCM

Sunday, January 22, 12

Page 16: Pragmatic Test Driven Development

Continuous Integration

BuildServer

Compilation

Executes Tests

Defines Status

Sunday, January 22, 12

Page 17: Pragmatic Test Driven Development

Continuous Integration

10MINUTE BUILD

Sunday, January 22, 12

Page 18: Pragmatic Test Driven Development

Test First Programming

Sunday, January 22, 12

Page 19: Pragmatic Test Driven Development

Test First Programming

Sunday, January 22, 12

Page 20: Pragmatic Test Driven Development

Test Driven Development

Sunday, January 22, 12

Page 21: Pragmatic Test Driven Development

Test Driven Development

Test

Code

Test

Sunday, January 22, 12

Page 22: Pragmatic Test Driven Development

Test Driven Development

Failing

Passing

Refactored

Sunday, January 22, 12

Page 23: Pragmatic Test Driven Development

Test Driven Development

Failing Acceptance Test

Failing Unit Test

Passing Unit Test

Refactor

Sunday, January 22, 12

Page 24: Pragmatic Test Driven Development

Test Driven Development

Code Code Code Code Test Code Code

Time

CodeTest

Time

CodeTest CodeTest Test

Sunday, January 22, 12

Page 25: Pragmatic Test Driven Development

Frameworks and Tools

Sunday, January 22, 12

Page 26: Pragmatic Test Driven Development

Frameworks And Tools

xUnitSunday, January 22, 12

Page 27: Pragmatic Test Driven Development

Frameworks And Tools

xUnit Language

JUnit Java

NUnit .Net

TestUnit Ruby

QUnit JavaScript

PhpUnit PHP

Sunday, January 22, 12

Page 28: Pragmatic Test Driven Development

Pair Programming

Sunday, January 22, 12

Page 29: Pragmatic Test Driven Development

Pair Programming

Write Test Write Code

Sunday, January 22, 12

Page 30: Pragmatic Test Driven Development

Tutorial #1

Sunday, January 22, 12

Page 31: Pragmatic Test Driven Development

Test Unit Fundamentals

test_strike_strike_ball_ball_ball

test_full_count

vs

Sunday, January 22, 12

Page 32: Pragmatic Test Driven Development

Test Unit Fundamentals

Setup

Assertion

Assertion

Assertion

Tear Down

Sunday, January 22, 12

Page 33: Pragmatic Test Driven Development

Test Unit Fundamentalsassert(test, msg = (nomsg = true; nil))

assert_equal(exp, act, msg = nil)

assert_no_match(regexp, string, msg=nil)

assert_not_equal(exp, act, msg=nil)

assert_not_nil(exp, msg=nil)

assert_not_same(expected, actual, message="")

assert_nothing_raised(*args)

assert_nothing_thrown(msg=nil)

assert_raise(*args, &b)

assert_respond_to(obj, meth, msg = nil)

Sunday, January 22, 12

Page 34: Pragmatic Test Driven Development

TDD RUles

1.Only write code that makes a test pass

2.Only write enough of a test to make it fail

3.Only write enough code to make a test pass

Sunday, January 22, 12

Page 35: Pragmatic Test Driven Development

Tutorial #1

In pairs, write a program that can play the game of hangman.

50mActivity Time

Sunday, January 22, 12

Page 36: Pragmatic Test Driven Development

Mocking & STUBBING

Mocks vs. Stubs

Indirect Outputs vs. Indirect Inputs

Objects vs. Methods

Behavior vs. State

Sunday, January 22, 12

Page 37: Pragmatic Test Driven Development

Mocking

Order

Warehouse

?

?

?

Warehouse

Sunday, January 22, 12

Page 38: Pragmatic Test Driven Development

Mocking

Order

Warehouse

WarehouseItem

order.items.each do |item| warehouse_item = Warehouse.find(item) warehouse_item.stock_reservation.reserveend

StockReservation

Sunday, January 22, 12

Page 39: Pragmatic Test Driven Development

Mocking

Order

Warehouse

Warehouse.reserve(items)

Sunday, January 22, 12

Page 40: Pragmatic Test Driven Development

Mocking

fake_warehouse = mock(Warehouse)

assert( fake_warehouse.received("reserve") .with(items), "Expected the warehouse to check its stock")

Sunday, January 22, 12

Page 41: Pragmatic Test Driven Development

STUBBING

CUSTOMER

“If any items are out-of-stock, the system should prevent the

order from completing”

Sunday, January 22, 12

Page 42: Pragmatic Test Driven Development

STUBBING

def test_out_of_stock order = Order.new item1 = Item.new(:sku => "abc") item2 = Item.new(:sku => "def") order.items = [item1, item2] stock_item1 = StockItem.new(:sku => 'zyx') ...end

Sunday, January 22, 12

Page 43: Pragmatic Test Driven Development

STUBBING

def test_invalid_items Warehouse.stub(:reserve) .and_raise(OutOfStockException) assert_raise(OutOfStockException) do order.complete endend

Sunday, January 22, 12

Page 44: Pragmatic Test Driven Development

Tutorial #2

Sunday, January 22, 12

Page 45: Pragmatic Test Driven Development

Tutorial #2

In pairs, write a program that implements Conway’s game of life.

45mActivity Time

Sunday, January 22, 12

Page 46: Pragmatic Test Driven Development

Game of Life

“The universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells, each of which is in one of two possible states, alive or dead. Every cell interacts with its eight neighbors, which are the cells that are horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur:”

Sunday, January 22, 12

Page 47: Pragmatic Test Driven Development

Game of Life: Rules

1 Any live cell with fewer than two live neighbors dies, as if caused by under-population.

2 Any live cell with two or three live neighbors lives on to the next generation.

3 Any live cell with more than three live neighbors dies, as if by overcrowding.

Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.4

Sunday, January 22, 12

Page 48: Pragmatic Test Driven Development

Closing

Sunday, January 22, 12

Page 49: Pragmatic Test Driven Development

Test Feedback

Listen to your tests

Sunday, January 22, 12

Page 50: Pragmatic Test Driven Development

Code Coverage

DEV

MANAGEMENT

“If we’re not at 90% code coverage you’re all working

on Saturday.”

“assert(true)”

Sunday, January 22, 12

Page 51: Pragmatic Test Driven Development

Continuously Integrate

Live and Die by the build

Sunday, January 22, 12

Page 52: Pragmatic Test Driven Development

Plan to Succeed

Write tests before you plan the implementation

BDD

Failing Unit Test

Passing Unit Test

Refactor

TDD

Sunday, January 22, 12


Top Related