+ All Categories
Home > Software > Test-driven development with Node.js

Test-driven development with Node.js

Date post: 20-Jul-2015
Category:
Upload: mirko-kiefer
View: 233 times
Download: 1 times
Share this document with a friend
17
Test-driven development with Node.js @mirkokiefer Mirko Kiefer - [email protected]
Transcript

Test-driven development with Node.js

@mirkokiefer Mirko Kiefer - [email protected]

What is TDD?

Why use TDD?• Less fear of change

• Increase productivity and focus

• Better communication in teams

• Improved software design

• Less bugs

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

Write failing test

• Imagine the interface you wish

• Does not have to compile

• Keep it simple

Make test pass

• Quickest solution possible

• Sins are allowed

• Fake it till you make it

Refactor

• Remove duplication

• If obvious, write “correct” implementation

• Write next failing test

Fake it till you make it!

How to fake it?

Dependency Injection

Enter proxyquire()

• Dependency injection without changing your code

• Does not fiddle with globals

Spies and stubs self-made

Spies and stubs Sinon.JS

Code coverage Istanbul

Code coverage

• Don’t be fanatic

• Code covered does not mean its tested

• You know which code is critical

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

Mirko Kiefer @mirkokiefer

[email protected]

Questions?


Recommended