18
REST API-LEVEL TDD WITH NODEJS Dang Viet Ha @ Tech Talk #2, Hanoi 2016

REST API level TDD with NodeJS

Embed Size (px)

Citation preview

REST API-LEVEL TDD With Nodejs

REST API-LEVEL TDD With NodejsDang Viet Ha @ Tech Talk #2, Hanoi 2016

agendaWhat is TDD?The Benefits and Limitations of TDDCommon Pitfalls of TDDREST-API TDD with Node.jsDemoQuestion?

What is TDD?TDD: Test Driven Development refers to a style of programming in which three activities are tightly interwovenCodingTesting (Unit Test)Design (Refactoring)Basic Philosophywrite a "single" unit test describing an aspect of the programrun the test, which should fail because the program lacks that featurewrite "just enough" code, the simplest possible, to make the test pass"refactor" the code until it conforms to the simplicity criteriarepeat, "accumulating" unit tests over time

What is TDD?

The Benefits and Limitations BenefitsWriting tests first require you to really consider what you want from the codeShort feedback loopReduced time in reworkLess time spent in the debuggerSimplification & Loose Coupling (DI)Improves quality and reduces bugs LimitationsBigger up-front costSome codes are difficult to write the test.Focus on micro-design not macro-designNeed to use mock to reproduce the real world.Cannot cover all functional testing (UI, DB, Network,)

Common PitfallsIndividual mistakesForgetting to run tests frequentlyWriting too many tests at onceWriting tests that are too large or coarse-grainedWriting overly trivial tests, for instance omitting assertionsWriting tests for trivial code, for instance assessorsTeam pitfallsPartial adoption - only a few developers on the team use TDDPoor maintenance of the test suite - most commonly leading to a test suite with a prohibitively long running timeAbandoned 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.jsREST-API: Express and MongooseAuthorization: PassportDependencies Injection: WagnerTest framework: MochaValidation & Assertion: AssertHTTP Request: Super-AgentTest And Watch task running: Gulp

REST-API

Mocha

Mocha

MOCHA

GULP TASK

DEMO

DEMO

DEMO

DEMO

DEMO

Q&A