Top Banner
Test-driven development with Node.js @mirkokiefer Mirko Kiefer - [email protected]
17

Test-driven development with Node.js

Jul 20, 2015

Download

Software

Mirko Kiefer
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Test-driven development with Node.js

Test-driven development with Node.js

@mirkokiefer Mirko Kiefer - [email protected]

Page 2: Test-driven development with Node.js

What is TDD?

Page 3: Test-driven development with Node.js

Why use TDD?• Less fear of change

• Increase productivity and focus

• Better communication in teams

• Improved software design

• Less bugs

Page 4: Test-driven development with Node.js

Test in layers

• Start with the public interface (API / user interface)

• Mock the next (non-implemented) layer underneath

• Repeat with implementing the next layer

• Example:user interface -> server API -> request handlers -> database

Page 5: Test-driven development with Node.js

Write failing test

• Imagine the interface you wish

• Does not have to compile

• Keep it simple

Page 6: Test-driven development with Node.js

Make test pass

• Quickest solution possible

• Sins are allowed

• Fake it till you make it

Page 7: Test-driven development with Node.js

Refactor

• Remove duplication

• If obvious, write “correct” implementation

• Write next failing test

Page 8: Test-driven development with Node.js

Fake it till you make it!

Page 9: Test-driven development with Node.js

How to fake it?

Page 10: Test-driven development with Node.js

Dependency Injection

Page 11: Test-driven development with Node.js

Enter proxyquire()

• Dependency injection without changing your code

• Does not fiddle with globals

Page 12: Test-driven development with Node.js

Spies and stubs self-made

Page 13: Test-driven development with Node.js

Spies and stubs Sinon.JS

Page 14: Test-driven development with Node.js

Code coverage Istanbul

Page 15: Test-driven development with Node.js

Code coverage

• Don’t be fanatic

• Code covered does not mean its tested

• You know which code is critical

Page 16: Test-driven development with Node.js

Keep it simple

• Do you really need tools for mocking and dependency injection?

• Tools introduce complexity and can slow you down

• Embrace concepts, not tools

Page 17: Test-driven development with Node.js

Mirko Kiefer @mirkokiefer

[email protected]

Questions?