Testing Node.js
Theory
Why Testing?
●Verification: more confidence in the absence
of bugs
●Better code
●Changes can be made without risk of breaking
existing features
Types of testing
1.Unit Testing
Tests individual units: e.g.: compare password
part of a login service
2.Integration Testing
Tests a complete service or end-end feature:
e.g.: complete login service
Unit Tests vs. Integration Tests
Unit Tests Integration Tests
Number of tests required for
n components with m paths
each: m*n
Number of tests required for n
components with m paths each: m^n??
(to be checked)
Fast Slow
More important than
integration tests
Still important to test end-end functionality
Agile and Testing
●One of the core parts of agile methodology is
TDD
●To reap the benefits of agile, TDD should be
followed
TDD vs. BDD
●TDD (Test driven development) is an approach
that advocates writing unit tests for all
functionality
●BDD (Behavior driven development) can be
seen as a form of TDD that uses product-owner
/ backlog friendly language in tests
Testing Node.js
Application
Testing tools
Testing framework Mocha
BDD library Chai (expect & should)
Mocking framework Sinon.js
Proxyquire
Code organization JavaScript classes
Why Multi-core?
●Decrease in latency
●Test using node siege benchmarking
var siege = require('siege');
// run cpu bound service benchmark
siege()
.on(3000)
.for(1000).times
.concurrent(100)
.get('/')
.attack();
Cluster Semantics
●Very simple to use
●Multi-core benefits with only a few lines of
code
●Code divided into two sections:
○One for master process
○One for worker processes
●Various events are available to communicate
between processes
Thank you

Testing Node.js.pdf

  • 1.
  • 2.
    Why Testing? ●Verification: moreconfidence in the absence of bugs ●Better code ●Changes can be made without risk of breaking existing features
  • 3.
    Types of testing 1.UnitTesting Tests individual units: e.g.: compare password part of a login service 2.Integration Testing Tests a complete service or end-end feature: e.g.: complete login service
  • 4.
    Unit Tests vs.Integration Tests Unit Tests Integration Tests Number of tests required for n components with m paths each: m*n Number of tests required for n components with m paths each: m^n?? (to be checked) Fast Slow More important than integration tests Still important to test end-end functionality
  • 5.
    Agile and Testing ●Oneof the core parts of agile methodology is TDD ●To reap the benefits of agile, TDD should be followed
  • 6.
    TDD vs. BDD ●TDD(Test driven development) is an approach that advocates writing unit tests for all functionality ●BDD (Behavior driven development) can be seen as a form of TDD that uses product-owner / backlog friendly language in tests
  • 7.
  • 8.
    Testing tools Testing frameworkMocha BDD library Chai (expect & should) Mocking framework Sinon.js Proxyquire Code organization JavaScript classes
  • 9.
    Why Multi-core? ●Decrease inlatency ●Test using node siege benchmarking var siege = require('siege'); // run cpu bound service benchmark siege() .on(3000) .for(1000).times .concurrent(100) .get('/') .attack();
  • 10.
    Cluster Semantics ●Very simpleto use ●Multi-core benefits with only a few lines of code ●Code divided into two sections: ○One for master process ○One for worker processes ●Various events are available to communicate between processes
  • 11.