tdd vs sql

49

Upload: guillaume-saint-etienne

Post on 26-Jun-2015

340 views

Category:

Technology


0 download

DESCRIPTION

Can you really (unit) test with a RDBMS? What drive your application: data or tests? Who's your master?

TRANSCRIPT

Page 1: Tdd vs SQL
Page 2: Tdd vs SQL

DOJO (COMING SOON)

https://github.com/guillaumeagile/AtelierCleanArchitecture2013/

/c#/CLEAN-OneBrandTwoShopsTwoUI_WithTests

Page 3: Tdd vs SQL

TESTING GOALS

1. Programmer errors

2. Design errors

3. Requirements errors

4. Systemic errors

Page 4: Tdd vs SQL

http://www.qualitystreet.fr

Page 5: Tdd vs SQL

UNIT OR NOT UNIT ?

Page 6: Tdd vs SQL

PROGRAMMER ERRORS

Unit Tests guarantee safe Refactoring

Page 7: Tdd vs SQL

DES TESTS RAPIDES

… ou rien !

Page 8: Tdd vs SQL

ISOLATION

One thing at a time!

Page 9: Tdd vs SQL

COMPLEXITY

In French : Combinatoire

Page 10: Tdd vs SQL

LA COMBINATOIRE FAIT PEUR

Page 11: Tdd vs SQL

INTEGRATION TESTS

5 composants qui ont chacun 50 cas de

fonctionnements

2 composants qui ont chacun 11 cas

différents

Page 12: Tdd vs SQL

INTEGRATION TESTS

Page 13: Tdd vs SQL

INTEGRATION TESTS

Page 14: Tdd vs SQL

UNITAIREMENT

5 x 50 = 250

2 x 11 = 22

Total: 277 tests

Page 15: Tdd vs SQL

REDUCE COMPLEXITY

Where does it come from?

Page 16: Tdd vs SQL

FROM THIS?

Page 17: Tdd vs SQL

OR THIS?

Page 18: Tdd vs SQL

GRAVITY

Do you know

Newton?

Page 19: Tdd vs SQL

A DATACENTRIC ARCHITECURE

Page 20: Tdd vs SQL

DATABASE IS A

Page 21: Tdd vs SQL

FROM THE CODE POINT OF VIEW

Database is a

Storage

Persitence

Service

Plug-in

Page 22: Tdd vs SQL

THE DATABASE IS A

Detail !

Page 23: Tdd vs SQL

MAKES YOU THINK TWICE

Which data to keep in your test and why?

Which data to keep in your code and why?

Page 24: Tdd vs SQL

ISOLATE IT

I don’t care

I want objects

I want to code

I want an application

Test One Thing at a Time

Minimize Dependencies

Page 25: Tdd vs SQL

CHANGE THE WAY YOU CODE

Page 26: Tdd vs SQL

PATTERN 1: REMOVE THE CORE DATA

DEPENDENCE

Page 27: Tdd vs SQL

ABSTRACT DATA TO A MODEL

Page 28: Tdd vs SQL

REPOSITORY PATTERN

DB = persistence

No more!

Page 29: Tdd vs SQL

PATTERN 2: CONSTRUCT AN IN-MEMORY CORE

DATA STACK.

Page 30: Tdd vs SQL

MOCK IT, FAKE IT, DEFER IT

Find a gateway

Page 31: Tdd vs SQL
Page 32: Tdd vs SQL

MAKES YOUR LIFE EASIER

I must set up a Test DB

What if someone else add sh*t in your test DB?

Test DB is growing and growing…

What if you loose you DB connection?

What if you loose it all?

Page 33: Tdd vs SQL

NO DEPENDENCE ON EXTERNAL STATE

• the tests must run the same

way every time they run

Page 34: Tdd vs SQL

IDEMPOTENT TEST

you are able to rerun something because the process of

running it did not change its state.

Page 35: Tdd vs SQL

CLOSE APPROXIMATION TO THE APPLICATION

ENVIRONMENT

With a Fake or a Mock

Page 36: Tdd vs SQL

WHAT ABOUT CONSTRAINS

They are logic in data

They are impossible to test

They are hard to maintain

Page 37: Tdd vs SQL

WHAT ABOUT TRANSACTIONS

Do you really need ACID ?

Page 38: Tdd vs SQL

WHAT ABOUT STORED PROCEDURES

They are pain in the ass!

They embed logic with data

They are hard to test

They are hard to maintain

Page 39: Tdd vs SQL

WHAT ABOUT TRIGGERS

They are evil

Page 40: Tdd vs SQL

DID I SAY NO (TO) SQL?

Page 41: Tdd vs SQL

CHANGE YOUR VIEW ON DATA

Is the DBA your master?

Page 42: Tdd vs SQL

STOP DATA FASCISM

Stop thinking MDD (Model Driven Design)

MCD in French

Think DDD

DOMAIN

DRIVEN

DESIGN

Page 43: Tdd vs SQL

FOCUSED INTEGRATION TESTS

Page 44: Tdd vs SQL

EXPLORATORY TESTING

Page 45: Tdd vs SQL

ONE BUG = ONE MISSING TEST

No unit test can tell you that you need more tests…

Exploration can.

Page 46: Tdd vs SQL

THERE’S ALWAYS A PATTERN

To be more and more isolated (SRP/OCP/LSP/ISP/DI)

• Factory

• Facade

• Visitor

• IoC ( Depency Injectors)

• ….

• MVP

• Humble Dialog ….

Page 47: Tdd vs SQL

ALL IS A MATTER OF CONCEPTS

Abstraction & Architecture

Page 48: Tdd vs SQL

CHANGE THE WAY YOU CODE

ALWAYS CODE AS YOU TEST: in isolation

-> Domain knows nothing about the infrastructure.

Page 49: Tdd vs SQL

CREDITS

http://visualstudiomagazine.com/articles/2009/09/01/eliminat

e-database-dependencies-in-test-driven-development.aspx

http://codebetter.com/jeremymiller/2005/10/12/unit-testing-

business-logic-without-tripping-over-the-database/

http://stackoverflow.com/questions/145131/whats-the-best-

strategy-for-unit-testing-database-driven-applications

http://www.jamesshore.com/Blog/Alternatives-to-Acceptance-

Testing.html

http://www.agiledata.org/essays/agileDataModeling.html

http://martinfowler.com/bliki/OrmHate.html

http://www.adam-

bien.com/roller/abien/entry/how_evil_are_actually_data