NFluent Brown bag lunch January 2014

43
AS YOU MEANT IT… NFluent: the craft you needed to boost your TDD Brown Bag Lunch - 2014 @tpierrain @cyrdup

description

Slides of the Brown Bag Lunch session at SG CIB, dedicated to NFluent. Video also available here: https://www.youtube.com/watch?v=fJuDLWJiIJc

Transcript of NFluent Brown bag lunch January 2014

Page 1: NFluent Brown bag lunch January 2014

AS YOU MEANT IT…

NFluent: the craft you needed to boost your TDD

Brown Bag Lunch - 2014 !!

@tpierrain @cyrdup

Page 2: NFluent Brown bag lunch January 2014

WHO ARE WE?

use case driven (blog) Many Cores (blog)

Page 3: NFluent Brown bag lunch January 2014

UNIT TESTS FROM THE TRENCHES…

Page 4: NFluent Brown bag lunch January 2014

COMMENTS?

Page 5: NFluent Brown bag lunch January 2014

IDEAL WORLD

Page 6: NFluent Brown bag lunch January 2014

HARD FACT #1 Tests assertions are needlessly difficult to write

!

Page 7: NFluent Brown bag lunch January 2014

HARD FACT #1 Tests assertions are needlessly difficult to write

!

Page 8: NFluent Brown bag lunch January 2014

HARD FACT #1 Tests assertions are needlessly difficult to write

!

Page 9: NFluent Brown bag lunch January 2014

HARD FACT #1

CONSEQUENCES

error-prone reluctance to write tests

relevance of tests?

Tests assertions are needlessly difficult to write

!

Page 10: NFluent Brown bag lunch January 2014

#1: WE DESERVE NO BRAINER ASSERTIONS!

Page 11: NFluent Brown bag lunch January 2014

HARD FACT #2Test intentions may be difficult to grasp

Page 12: NFluent Brown bag lunch January 2014

HARD FACT #2

CONSEQUENCES

tests are hard to maintain loss of trust in existing tests

Removal of failing tests?

Test intentions may be difficult to grasp

Page 13: NFluent Brown bag lunch January 2014

#2: TESTS INTENTIONS SHOULD BE OBVIOUS!

Page 14: NFluent Brown bag lunch January 2014

HARD FACT #3

When reliable… error messages are often unhelpful

Page 15: NFluent Brown bag lunch January 2014

HARD FACT #3

CONSEQUENCES

Need to debug the failing test to understandslowwww… TDD feedback loop

Poor efficiency?!?

When reliable… error messages are often unhelpful

Page 16: NFluent Brown bag lunch January 2014

#3:WE WANT TRUSTWORTHY & HELPFUL ERROR MESSAGES!

Page 17: NFluent Brown bag lunch January 2014

#3:WE WANT TRUSTWORTHY & HELPFUL ERROR MESSAGES!

Page 18: NFluent Brown bag lunch January 2014

TDD IS NOT EASY…

Page 19: NFluent Brown bag lunch January 2014

TDD IS NOT EASY…

… but NFluent will greatly help you

Page 20: NFluent Brown bag lunch January 2014

!! !!!!!!!!!!!!!!!!!!!!!!!

(source: http://www.thefreedictionary.com/fluent)

UBIQUITOUS LANGUAGE

Fluent [ˈfluːənt] adj

1. spoken or written with ease: fluent French. 2. able to speak or write smoothly, easily, or readily: fluent

in three languages.

3. smooth; easy; graceful: fluent motion

4. flowing or capable of flowing; fluid

![from Latin: fluere to flow, stream]

Page 21: NFluent Brown bag lunch January 2014

#1: NO BRAINER ASSERTIONS!

NFLUENT’S ANSWERS

#2: OBVIOUS TESTS INTENTIONS!

#3: TRUSTWORTHY & HELPFUL ERROR MESSAGES!

Page 22: NFluent Brown bag lunch January 2014

#1: NO BRAINER ASSERTIONS!

NFLUENT’S ANSWERS

A unique entry point for assertions (Check.That)

IntelliSense guided writing (a.k.a. the super-duper-happy dot xp)

#2: OBVIOUS TESTS INTENTIONS!

#3: TRUSTWORTHY & HELPFUL ERROR MESSAGES!

Page 23: NFluent Brown bag lunch January 2014

#1: NO BRAINER ASSERTIONS!

NFLUENT’S ANSWERS

Natural language assertions

A unique entry point for assertions (Check.That)

IntelliSense guided writing (a.k.a. the super-duper-happy dot xp)

#2: OBVIOUS TESTS INTENTIONS!

#3: TRUSTWORTHY & HELPFUL ERROR MESSAGES!

Page 24: NFluent Brown bag lunch January 2014

#1: NO BRAINER ASSERTIONS!

NFLUENT’S ANSWERS

Natural language assertions

A unique entry point for assertions (Check.That)

IntelliSense guided writing (a.k.a. the super-duper-happy dot xp)

Non ambiguous, contextualized and explicit error messages

#2: OBVIOUS TESTS INTENTIONS!

#3: TRUSTWORTHY & HELPFUL ERROR MESSAGES!

Page 25: NFluent Brown bag lunch January 2014

COMBINING THOSE 3 WISHES, WE CAN REACH OUR IDEAL: EFFICIENT TDD!

Page 26: NFluent Brown bag lunch January 2014

!

!

!

!

!

!!

NFLUENT SAMPLES

Page 27: NFluent Brown bag lunch January 2014

DEMO

Page 28: NFluent Brown bag lunch January 2014

• NFluent is

• An OSS .NET library for fluent assertions

• Independent and compliant with all major .NET test runners

• Directly inspired by the awesome Java FEST assert library

• Available on

IN A FEW WORDS

Page 29: NFluent Brown bag lunch January 2014

• A fully extensible model

• No need to wait the NFluent team to add your own assertions on any kind of ‘value’

• The opportunity to use your own ubiquitous language (DSL) from within your tests

!

• Some extra candies

• Like the Properties extension method for IEnumerable

• The HasFieldsWithSameValues(anonymous class)

BONUS FEATURES

Page 30: NFluent Brown bag lunch January 2014

!

!

IN THE WILD

tpierrain malatrhwydupdob

Page 31: NFluent Brown bag lunch January 2014

FINAL QUESTION

Page 32: NFluent Brown bag lunch January 2014

!

!

!

!

!

Does your test framework dictate the way you work,

or is it the other way around?

FINAL QUESTION

Page 33: NFluent Brown bag lunch January 2014

APPLY TDD!

Page 34: NFluent Brown bag lunch January 2014

APPLY TDD!

Use NFluent!

Page 35: NFluent Brown bag lunch January 2014

APPLY TDD!

Use NFluent!

Page 36: NFluent Brown bag lunch January 2014

APPLY TDD!

Use NFluent!

http://www.n-fluent.net

Page 37: NFluent Brown bag lunch January 2014
Page 38: NFluent Brown bag lunch January 2014

APPENDIX

Page 39: NFluent Brown bag lunch January 2014

TDD: A WORKFLOW

Page 40: NFluent Brown bag lunch January 2014

(like: FluentAssertion, Sharp Tests Ex, etc.)

• Their usage of lambda expression predicates hurts the fluent experience

new[] { 1, 2, 3 }.Should().Contain(item => item > 3, "at least {0} item should be larger than 3", 1);

• (Red is dead, but) Should is weak…

• We aim to be more ambitious in term of fluentness

NFLUENT VS. OTHER ASSERTION LIBRARIES?

Page 41: NFluent Brown bag lunch January 2014

• For NFluent contributors

• No warning (all warn as ERROR)

• No StyleCop warning (full rules)

• 100% of test coverage - all test passed of course!

• The entire build lasts less than a minute (including all unit tests)

DEFINITION OF DONE

Page 42: NFluent Brown bag lunch January 2014

!

!

!

!

!

!!

BY TEST DEVELOPMENT DRIVEN IS?

Page 43: NFluent Brown bag lunch January 2014

Use NFluent!

!

!

!!

WRITE VALUABLE TESTS

(NFluent logo © rhwy)

!

http://www.n-fluent.net

Thank you!