SlideShare a Scribd company logo
REST API-LEVEL TDD WITH
NODEJS
Dang Viet Ha @ Tech Talk #2, Hanoi 2016
AGENDA
 What is TDD?
 The Benefits and Limitations of TDD
 Common Pitfalls of TDD
 REST-API TDD with Node.js
 Demo
 Question?
WHAT IS TDD?
 TDD: Test Driven Development refers to a style of programming
in which three activities are tightly interwoven
1. Coding
2. Testing (Unit Test)
3. Design (Refactoring)
 Basic Philosophy
1. write a "single" unit test describing an aspect of the program
2. run the test, which should fail because the program lacks that feature
3. write "just enough" code, the simplest possible, to make the test pass
4. "refactor" the code until it conforms to the simplicity criteria
5. repeat, "accumulating" unit tests over time
WHAT IS TDD?
THE BENEFITS AND LIMITATIONS
 Benefits
1. Writing tests first require you to really consider what you want from the code
2. Short feedback loop
3. Reduced time in rework
4. Less time spent in the debugger
5. Simplification & Loose Coupling (DI)
6. Improves quality and reduces bugs
 Limitations
1. Bigger up-front cost
2. Some codes are difficult to write the test.
3. Focus on micro-design not macro-design
4. Need to use mock to reproduce the real world.
5. Cannot cover all functional testing (UI, DB, Network,…)
COMMON PITFALLS
 Individual mistakes
1. Forgetting to run tests frequently
2. Writing too many tests at once
3. Writing tests that are too large or coarse-grained
4. Writing overly trivial tests, for instance omitting assertions
5. Writing tests for trivial code, for instance assessors
 Team pitfalls
1. Partial adoption - only a few developers on the team use TDD
2. Poor maintenance of the test suite - most commonly leading to a test suite
with a prohibitively long running time
3. Abandoned test suite (i.e. seldom or never run) - sometimes as a result of
poor maintenance, sometimes as a result of team turnover
REST-API TDD WITH NODE.JS
 REST-API: Express and Mongoose
 Authorization: Passport
 Dependencies Injection: Wagner
 Test framework: Mocha
 Validation & Assertion: Assert
 HTTP Request: Super-Agent
 Test And Watch task running: Gulp
REST-API
MOCHA
MOCHA
MOCHA
GULP TASK
DEMO
DEMO
DEMO
DEMO
DEMO
Q&A

More Related Content

PPTX
Android tdd
PPTX
PPTX
TDD- Test Driven Development
PDF
Code Review
PDF
Test Driven Development with OSGi - Balázs Zsoldos
PDF
Test driven development_continuous_integration
PDF
Code Review for iOS
PPTX
How to improve code quality for iOS apps?
Android tdd
TDD- Test Driven Development
Code Review
Test Driven Development with OSGi - Balázs Zsoldos
Test driven development_continuous_integration
Code Review for iOS
How to improve code quality for iOS apps?

What's hot (18)

PPTX
Unit tests benefits
PDF
Code Review
PPTX
RESTful Microservices
PPTX
Code Review
PDF
Android Devops : Master Continuous Integration and Delivery
PPT
Introduction to test programming
PDF
Code Review: How and When
PPTX
Tdd com Java
PDF
Introduction to test_driven_development
ODP
Tdd in php a brief example
PPT
Code review
PDF
Introduction to Robot Framework – Exove
PPTX
What Is Cucumber?
PPTX
Code Review tool for personal effectiveness and waste analysis
PDF
Functional Tests Automation with Robot Framework
PPTX
Code review
Unit tests benefits
Code Review
RESTful Microservices
Code Review
Android Devops : Master Continuous Integration and Delivery
Introduction to test programming
Code Review: How and When
Tdd com Java
Introduction to test_driven_development
Tdd in php a brief example
Code review
Introduction to Robot Framework – Exove
What Is Cucumber?
Code Review tool for personal effectiveness and waste analysis
Functional Tests Automation with Robot Framework
Code review
Ad

Similar to REST API-LEVEL TDD With Nodejs (20)

PPTX
Test Driven Development
PPT
Test Driven Development
PPTX
Test Driven Development
PPTX
Test Driven Development
PPTX
Test driven development
PPTX
Test driven development
PPTX
Test driven development
PPTX
Test driven development
PPTX
Test driven development
PPTX
Test driven development
PDF
Test Driven Development
PDF
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
PPTX
Tdd is not about testing (C++ version)
KEY
Test Driven Development - Tulsa TechFest 2009
KEY
Test Driven Development - 09/2009
PPTX
Test-Driven Development In Action
PPTX
Test driven development
KEY
Test Driven Development
PPTX
Understanding TDD - theory, practice, techniques and tips.
PPT
Test Driven Development - Overview and Adoption
Test Driven Development
Test Driven Development
Test Driven Development
Test Driven Development
Test driven development
Test driven development
Test driven development
Test driven development
Test driven development
Test driven development
Test Driven Development
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
Tdd is not about testing (C++ version)
Test Driven Development - Tulsa TechFest 2009
Test Driven Development - 09/2009
Test-Driven Development In Action
Test driven development
Test Driven Development
Understanding TDD - theory, practice, techniques and tips.
Test Driven Development - Overview and Adoption
Ad

REST API-LEVEL TDD With Nodejs

  • 1. REST API-LEVEL TDD WITH NODEJS Dang Viet Ha @ Tech Talk #2, Hanoi 2016
  • 2. AGENDA  What is TDD?  The Benefits and Limitations of TDD  Common Pitfalls of TDD  REST-API TDD with Node.js  Demo  Question?
  • 3. WHAT IS TDD?  TDD: Test Driven Development refers to a style of programming in which three activities are tightly interwoven 1. Coding 2. Testing (Unit Test) 3. Design (Refactoring)  Basic Philosophy 1. write a "single" unit test describing an aspect of the program 2. run the test, which should fail because the program lacks that feature 3. write "just enough" code, the simplest possible, to make the test pass 4. "refactor" the code until it conforms to the simplicity criteria 5. repeat, "accumulating" unit tests over time
  • 5. THE BENEFITS AND LIMITATIONS  Benefits 1. Writing tests first require you to really consider what you want from the code 2. Short feedback loop 3. Reduced time in rework 4. Less time spent in the debugger 5. Simplification & Loose Coupling (DI) 6. Improves quality and reduces bugs  Limitations 1. Bigger up-front cost 2. Some codes are difficult to write the test. 3. Focus on micro-design not macro-design 4. Need to use mock to reproduce the real world. 5. Cannot cover all functional testing (UI, DB, Network,…)
  • 6. COMMON PITFALLS  Individual mistakes 1. Forgetting to run tests frequently 2. Writing too many tests at once 3. Writing tests that are too large or coarse-grained 4. Writing overly trivial tests, for instance omitting assertions 5. Writing tests for trivial code, for instance assessors  Team pitfalls 1. Partial adoption - only a few developers on the team use TDD 2. Poor maintenance of the test suite - most commonly leading to a test suite with a prohibitively long running time 3. Abandoned test suite (i.e. seldom or never run) - sometimes as a result of poor maintenance, sometimes as a result of team turnover
  • 7. REST-API TDD WITH NODE.JS  REST-API: Express and Mongoose  Authorization: Passport  Dependencies Injection: Wagner  Test framework: Mocha  Validation & Assertion: Assert  HTTP Request: Super-Agent  Test And Watch task running: Gulp
  • 10. MOCHA
  • 11. MOCHA
  • 13. DEMO
  • 14. DEMO
  • 15. DEMO
  • 16. DEMO
  • 17. DEMO
  • 18. Q&A