how to practice tdd without shooting yourself in the foot

19
Dennis Doomen | @ddoomen | Aviva Solutions | The Continuous Improver How To Practice TDD without shooting yourself in the foot

Upload: dennis-doomen

Post on 09-Jan-2017

392 views

Category:

Technology


0 download

TRANSCRIPT

Dennis Doomen | @ddoomen | Aviva Solutions | The Continuous Improver

How To Practice TDDwithout shooting yourself in the foot

Dennis DoomenThe Continuous Improver

19 years of experiencePrincipal Consultant @ Aviva Solutions

Codes in C#, JavaScript and PowerShellDesigns using TDD, SOLID, YAGNI, WTF

Architects using DDD, CQRS, Event Sourcing

Author of www.fluentassertions.com andwww.csharpcodingguidelines.com

Blogs at www.continuousimprover.com Tweets at @ddoomen

An opinionated definition

A great unit test…

• Is fast (i.e. couple of ms)• Runs in-memory• Has no I/O-bound dependencies• Has no static dependencies• Causes no side-effects• Should be parallelizable• Can run in any order• Has the right scope.

Test Driven Development means…

• Write a great unit test• Generate code• Ensure test fails for the right

reason• Implement the real deal• Ensure test succeeds• Identify alternative scenarios• Repeat twice• Refactor.

Defining the scope of testing

Command Handlers

Commands

Domain Model

Event Store

Events

App

Query Store

RavenDB

ProjectorsEvents

API Controller

Projections

Events

The principles of great unit tests

Test small before you test large

If it’s not important for the test, it’s

very important to hide it

Crystal-clear cause and effect

Reads like a book

Avoids DRY

Copy three times beforerefactoring

Applying the Practices in Practice

The Practices

• Define the boundary carefully• Use BDD or AAA when applicable• Don’t repeat the context in names• Don’t use technical names• Avoid constants• Use Test Data Builders for the irrelevant

parts• Show relevant dependencies• Only assert the relevant parts• Keep refactoring• Keep out of the debugger hell.

?

Recommended Resources

• Example codehttps://github.com/dennisdoomen/LiquidProjections/tree/TddDemoV2

• Chillhttps://github.com/Erwinvandervalk/Chill

• Fluent Assertionswww.fluentassertions.com

• Laws of Jeremy D. Millerhttp://codebetter.com/jeremymiller/2005/10/21/haacked-on-tdd-and-jeremys-first-rule-of-tdd/

• Xunit Patternshttp://xunitpatterns.com/

• Liquid Projectionshttps://github.com/dennisdoomen/LiquidProjections

• Test data buildershttp://www.natpryce.com/articles/000714.html