agile testing best practices

45
Agile Testing Best Practices Stephen Ritchie DCAST March Meeting 19-Mar-2013

Upload: stephen-ritchie

Post on 02-Dec-2014

3.018 views

Category:

Documents


5 download

DESCRIPTION

Have you ever bumped into a wall with your automated tests? Many developers bump into various roadblocks and hurdles when writing test code. Are your test methods starting to fail because the code-under-test uses the current date and time? Are your automated integration tests failing because the database they integrate with keeps changing? Do you have an explosion of test methods, with the ratio of test code to code-under-test way too high? Is your effort to refactor and improve code overwhelmed by the time it takes to rewrite all those failing unit tests? This presentation is about clearing away Agile testing obstacles, avoiding common pitfalls, and staying away from dangerous practices.

TRANSCRIPT

Page 1: Agile Testing Best Practices

Agile Testing Best Practices

Stephen RitchieDCAST March Meeting19-Mar-2013

Page 2: Agile Testing Best Practices

Excella Consulting

2

3

1

Agenda

- 2 -

Motivation

Principles

Obstacles

Page 3: Agile Testing Best Practices

Excella Consulting

Motivation

Why Test Software?

Page 4: Agile Testing Best Practices
Page 5: Agile Testing Best Practices

Excella Consulting

Chrysler New Yorker

Page 6: Agile Testing Best Practices

Excella Consulting

Motivation

Why Write Automated

Tests?

Page 7: Agile Testing Best Practices

Excella Consulting

Achieve Desired Results

• Software costs too much• Users demand quality• Testing takes too long• New features take too long

Page 8: Agile Testing Best Practices

Excella Consulting

Microscope: Visibility and Insight

Page 9: Agile Testing Best Practices

Excella Consulting

Smoke Detector: Problem Detection

Page 10: Agile Testing Best Practices

Excella Consulting

Weather Satellite: Advanced Warning

Page 11: Agile Testing Best Practices

Software Works

Make Sure

As Intended

Automated Tests

Page 12: Agile Testing Best Practices

Excella Consulting

2

3

Agenda

- 12 -

Motivation

Principles

Obstacles

1

Page 13: Agile Testing Best Practices

Excella Consulting

Agile Test Pyramid: Vision

Engineers

Testers

Aut

omat

ed

http://bit.ly/10QubsyGoogle “Agile Test Pyramid”

Page 14: Agile Testing Best Practices

Excella Consulting

Agile Test Pyramid: Reality

http://bit.ly/10QpUFGIce-Cream Cone Anti-Pattern

Page 15: Agile Testing Best Practices

Excella Consulting

Agile Test Quadrants

Page 16: Agile Testing Best Practices

Excella Consulting

Principles

1. Unit Test

Developer Tests“Intention Checking”

Page 17: Agile Testing Best Practices

Excella Consulting

Principles

2. Automate• Always running• Can't be bargained with• Can't be reasoned with• Tests don't feel pity or

remorse or fear• Absolutely will not stop,

ever, until you deliver a quality software product.

Page 18: Agile Testing Best Practices

Excella Consulting

Principles

2. Automate• CI Server

• Per Commit• Overnight Functional• Smoke Testing• Stability Testing• Performance/Load

• Automate Deployments• Project “Dashboard”

Page 19: Agile Testing Best Practices

Excella Consulting

Principles

3. Zero Configuration*

I can run your tests,You can run mine.

* One-time configuration is okay

Page 20: Agile Testing Best Practices

Excella Consulting

Principles

4. Fast

All tests run time efficiently

Page 21: Agile Testing Best Practices

Excella Consulting

Principles

5. Clear Results

Pass/Fail

Focused Test

Isolates Issue

Page 22: Agile Testing Best Practices

Excella Consulting

Principles

6. Easy to Maintain

Conventional

Brief

Page 23: Agile Testing Best Practices

Excella Consulting

Principles

7. TimelyTest-Driven Development (TDD)

Test As-It’s-Built

Test As-It’s-Fixed

Page 24: Agile Testing Best Practices

Excella Consulting

3

Agenda

- 24 -

Motivation

Principles

Obstacles

1

2

Page 25: Agile Testing Best Practices

Excella Consulting

Requirements, Requirements, Requirements

•Too Abstract•Changing•Over Specification

Obstacle 1

Page 26: Agile Testing Best Practices
Page 27: Agile Testing Best Practices

Excella Consulting

Specification by Example

Examples & Feature Files

Page 28: Agile Testing Best Practices

Excella Consulting

One Primary Assert To Rule Them All

One Primary Assert

Page 29: Agile Testing Best Practices

Excella Consulting

Time Crunch

Obstacle 2

Time Crunch

Page 30: Agile Testing Best Practices

Excella Consulting

Four Ways to Fake Time

• Virtual Machine• Isolate The System

• Inspect The Clock

• Dummy IClock

Fake Time

Page 31: Agile Testing Best Practices

Real System Clock

Dummy Clock

IClock Interface

System Under Test

Page 32: Agile Testing Best Practices

Excella Consulting

Database Killed The Integration Test

Obstacle 3

DatabaseIntegration

Page 33: Agile Testing Best Practices

Excella Consulting

Fixture Setup and Data Arrangement

Page 34: Agile Testing Best Practices

Excella Consulting

Fixture Setup and Data Arrangement

• Schema Migration– RoundhousE– Flyway Db– Liquibase

• Data Arrangement– DbUnit &

NDbUnit

Page 35: Agile Testing Best Practices

Excella Consulting

Now We Have Too Much Test Code

Obstacle 4

Explosion ofTest Code

Page 36: Agile Testing Best Practices

Excella Consulting

Monitor Test Code Growth Rate

Control Growth• Monitor The Ratio

• Data-Drive Tests

• Boundary Analysis

Page 37: Agile Testing Best Practices
Page 38: Agile Testing Best Practices

Excella Consulting

Bad Coupling

Obstacle 5Unhelpful Reuse

Unhelpful Repetition

Unhelpful Coupling

Page 39: Agile Testing Best Practices

Excella Consulting

In Test Code, Do Repeat Yourself ... Do Repeat Yourself

Test Code Is Different• Avoid Inheritance Reuse• Use “Context” Helpers• Repetition Is Better Than Coupling

Page 40: Agile Testing Best Practices
Page 41: Agile Testing Best Practices

Excella Consulting

Agenda

- 41 -

Motivation

Principles

Obstacles

1

2

3

Page 42: Agile Testing Best Practices

Excella Consulting

Of Course It’s Safe … After You

Page 43: Agile Testing Best Practices

Excella Consulting

Shameless Self Promotion Time!

• “Best Practices” Initiative• Tips and Tricks• Generate Ideas

• Quantifying Value• Biases & Aversions• Tools & Technologies

• Avoid Making the Same Mistake Once.

Page 44: Agile Testing Best Practices

Excella Consulting

Code and Slides

• Code: https://github.com/ruthlesshelp

• Slides: http://www.slideshare.net/ruthlesshelp

Page 45: Agile Testing Best Practices

Excella Consulting

Contact Me

• Email: [email protected]• Twitter: @ruthlesshelp• Blog: http://ruthlesslyhelpful.net• LinkedIn: http://www.linkedin.com/in/

sritchie