Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Testing Overview

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →

Testing Overview

A short overview of different types of testing

Avatar for Hardy Jones

Hardy Jones

August 18, 2015

More Decks by Hardy Jones

Other Decks in Programming

Transcript

  1. Unit Test Result of a function Visible effects of a

    procedure Message sent from an object
  2. Integration Test Logging to a file Clicking a button and

    getting a POST request Ensuring two objects communicate
  3. But, what are the downsides? “...program testing can be a

    very effective way to show the presence of bugs, but is hopelessly inadequate for showing their absence.” - E.W. Disjkstra
  4. var express = require('express'); var app = express(); app.get('/', function

    (req, res) { res.send('Hello World!'); }); var server = app.listen(3000, function () { var host = server.address().address; var port = server.address().port; console.log('Example app listening at http://%s:%s', host, port); });
  5. var express = require('express'); var app = express(); app.get('/', function

    (req, res) { res.send('Hello World!'); }); var server = app.listen(3000, function () { var host = server.address().address; var port = server.address().port; console.log('Example app listening at http://%s:%s', host, port); });
  6. var express = require('express'); var app = express(); app.get('/', function

    (req, res) { res.send('Hello World!'); }); var server = app.listen(3000, function () { var host = server.address().address; var port = server.address().port; console.log('Example app listening at http://%s:%s', host, port); });
  7. var express = require('express'); var app = express(); app.get('/', function

    (req, res) { res.send('Hello World!'); }); var server = app.listen(3000, function () { var host = server.address().address; var port = server.address().port; console.log('Example app listening at http://%s:%s', host, port); });
  8. var express = require('express'); var app = express(); app.get('/', function

    (req, res) { res.send('Hello World!'); }); var server = app.listen(3000, function () { var host = server.address().address; var port = server.address().port; console.log('Example app listening at http://%s:%s', host, port); });
  9. var express = require('express'); var app = express(); app.get('/', function

    (req, res) { res.send('Hello World!'); }); var server = app.listen(3000, function () { var host = server.address().address; var port = server.address().port; console.log('Example app listening at http://%s:%s', host, port); });
  10. var express = require('express'); var app = express(); app.get('/', function

    (req, res) { res.send('Hello World!'); }); var server = app.listen(3000, function () { var host = server.address().address; var port = server.address().port; console.log('Example app listening at http://%s:%s', host, port); });
  11. var express = require('express'); var app = express(); app.get('/', function

    (req, res) { res.send('Hello World!'); }); var server = app.listen(3000, function () { var host = server.address().address; var port = server.address().port; console.log('Example app listening at http://%s:%s', host, port); });
  12. var express = require('express'); var app = express(); app.get('/', function

    (req, res) { res.send('Hello World!'); }); var server = app.listen(3000, function () { var host = server.address().address; var port = server.address().port; console.log('Example app listening at http://%s:%s', host, port); });
  13. var express = require('express'); var app = express(); app.get('/', function

    (req, res) { res.send('Hello World!'); }); var server = app.listen(3000, function () { var host = server.address().address; var port = server.address().port; console.log('Example app listening at http://%s:%s', host, port); });
  14. var express = require('express'); var app = express(); app.get('/', hello);

    function hello(req, res) { res.send('Hello World!'); } var server = app.listen(3000, function () { var host = server.address().address; var port = server.address().port; console.log('Example app listening at http://%s:%s', host, port); });
  15. var express = require('express'); var app = express(); app.get('/', function

    (req, res) { res.send('Hello World!'); }); var server = app.listen(3000, function () { var host = server.address().address; var port = server.address().port; console.log('Example app listening at http://%s:%s', host, port); });
  16. var assert = require('assert'); var request = require('request'); var app

    = require('./app'); describe('Routing to /', function() { it('should respond with "Hello World!"', function(done) { app.listen(3000, function() { request('http://localhost:3000/', function(err, res, body) { assert.equal(body, 'Hello World!'); done(); }); }); }); });
  17. var assert = require('assert'); var request = require('request'); var app

    = require('./app'); describe('Routing to /', function() { it('should respond with "Hello World!"', function(done) { app.listen(3000, function() { request('http://localhost:3000/', function(err, res, body) { assert.equal(body, 'Hello World!'); done(); }); }); }); });
  18. var assert = require('assert'); var request = require('request'); var app

    = require('./app'); describe('Routing to /', function() { it('should respond with "Hello World!"', function(done) { app.listen(3000, function() { request('http://localhost:3000/', function(err, res, body) { assert.equal(body, 'Hello World!'); done(); }); }); }); });
  19. var assert = require('assert'); var request = require('request'); var app

    = require('./app'); describe('Routing to /', function() { it('should respond with "Hello World!"', function(done) { app.listen(3000, function() { request('http://localhost:3000/', function(err, res, body) { assert.equal(body, 'Hello World!'); done(); }); }); }); });
  20. var assert = require('assert'); var request = require('request'); var app

    = require('./app'); describe('Routing to /', function() { it('should respond with "Hello World!"', function(done) { app.listen(3000, function() { request('http://localhost:3000/', function(err, res, body) { assert.equal(body, 'Hello World!'); done(); }); }); }); });
  21. var assert = require('assert'); var request = require('request'); var app

    = require('./app'); describe('Routing to /', function() { it('should respond with "Hello World!"', function(done) { app.listen(3000, function() { request('http://localhost:3000/', function(err, res, body) { assert.equal(body, 'Hello World!'); done(); }); }); }); });
  22. var assert = require('assert'); var request = require('request'); var app

    = require('./app'); describe('Routing to /', function() { it('should respond with "Hello World!"', function(done) { app.listen(3000, function() { request('http://localhost:3000/', function(err, res, body) { assert.equal(body, 'Hello World!'); done(); }); }); }); });
  23. var assert = require('assert'); var request = require('request'); var app

    = require('./app'); describe('Routing to /', function() { it('should respond with "Hello World!"', function(done) { app.listen(3000, function() { request('http://localhost:3000/', function(err, res, body) { assert.equal(body, 'Hello World!'); done(); }); }); }); });
  24. var assert = require('assert'); var request = require('request'); var app

    = require('./app'); describe('Routing to /', function() { it('should respond with "Hello World!"', function(done) { app.listen(3000, function() { request('http://localhost:3000/', function(err, res, body) { assert.equal(body, 'Hello World!'); done(); }); }); }); });
  25. var assert = require('assert'); var request = require('request'); var app

    = require('./app'); describe('Routing to /', function() { it('should respond with "Hello World!"', function(done) { app.listen(3000, function() { request('http://localhost:3000/', function(err, res, body) { assert.equal(body, 'Hello World!'); done(); }); }); }); });
  26. var assert = require('assert'); var request = require('request'); var app

    = require('./app'); describe('Routing to /', function() { it('should respond with "Hello World!"', function(done) { app.listen(3000, function() { request('http://localhost:3000/', function(err, res, body) { assert.equal(body, 'Hello World!'); done(); }); }); }); });
  27. var assert = require('assert'); var request = require('request'); var app

    = require('./app'); describe('Routing to /', function() { it('should respond with "Hello World!"', function(done) { app.listen(3000, function() { request('http://localhost:3000/', function(err, res, body) { assert.equal(body, 'Hello World!'); done(); }); }); }); });
  28. var assert = require('assert'); var request = require('request'); var app

    = require('./app'); describe('Routing to /', function() { it('should respond with "Hello World!"', function(done) { app.listen(3000, function() { request('http://localhost:3000/', function(err, res, body) { assert.equal(body, 'Hello World!'); done(); }); }); }); });
  29. var assert = require('assert'); var request = require('request'); var app

    = require('./app'); describe('Routing to /', function() { it('should respond with "Hello World!"', function(done) { app.listen(3000, function() { request('http://localhost:3000/', function(err, res, body) { assert.equal(body, 'Hello World!'); done(); }); }); }); });
  30. var assert = require('assert'); var request = require('request'); var app

    = require('./app'); describe('Routing to /', function() { it('should respond with "Hello World!"', function(done) { app.listen(3000, function() { request('http://localhost:3000/', function(err, res, body) { assert.equal(body, 'Hello World!'); done(); }); }); }); });
  31. var assert = require('assert'); var request = require('request'); var app

    = require('./app'); describe('Routing to /', function() { it('should respond with "Hello World!"', function(done) { app.listen(3000, function() { request('http://localhost:3000/', function(err, res, body) { assert.equal(body, 'Hello World!'); done(); }); }); }); });
  32. var assert = require('assert'); var request = require('request'); var app

    = require('./app'); describe('Routing to /', function() { it('should respond with "Hello World!"', function(done) { app.listen(3000, function() { request('http://localhost:3000/', function(err, res, body) { assert.equal(body, 'Hello World!'); done(); }); }); }); });
  33. ➜ testing npm test > [email protected] test /home/joneshf/presentations/testing > mocha

    integration.js Routing to / ✓ should respond with "Hello World!" 1 passing (27ms)
  34. ➜ testing npm test > [email protected] test /home/joneshf/presentations/testing > mocha

    integration.js Routing to / ✓ should respond with "Hello World!" 1 passing (27ms)
  35. ➜ testing npm test > [email protected] test /home/joneshf/presentations/testing > mocha

    integration.js Routing to / ✓ should respond with "Hello World!" 1 passing (27ms)
  36. ➜ testing npm test > [email protected] test /home/joneshf/presentations/testing > mocha

    integration.js Routing to / ✓ should respond with "Hello World!" 1 passing (27ms)
  37. var express = require('express'); var app = express(); app.get('/', function

    (req, res) { res.send('Hello World!'); }); var server = app.listen(3000, function () { var host = server.address().address; var port = server.address().port; console.log('Example app listening at http://%s:%s', host, port); });
  38. var express = require('express'); var app = express(); app.get('/', hello);

    function hello(req, res) { res.send('Hello World!'); } var server = app.listen(3000, function () { var host = server.address().address; var port = server.address().port; console.log('Example app listening at http://%s:%s', host, port); });
  39. ➜ testing npm test > [email protected] test /home/joneshf/presentations/testing > mocha

    integration.js Routing to / ✓ should respond with "Hello World!" 1 passing (27ms)
  40. var sinon = require('sinon'); var hello = require('./app').hello; describe('hello', function()

    { it('should invoke `Response#send` with "Hello World!"', function() { var response = {send: function() {}}; var responseMock = sinon.mock(response); responseMock.expects('send').once().withArgs('Hello World!'); hello(null, response); responseMock.verify(); }); });
  41. var sinon = require('sinon'); var hello = require('./app').hello; describe('hello', function()

    { it('should invoke `Response#send` with "Hello World!"', function() { var response = {send: function() {}}; var responseMock = sinon.mock(response); responseMock.expects('send').once().withArgs('Hello World!'); hello(null, response); responseMock.verify(); }); });
  42. var sinon = require('sinon'); var hello = require('./app').hello; describe('hello', function()

    { it('should invoke `Response#send` with "Hello World!"', function() { var response = {send: function() {}}; var responseMock = sinon.mock(response); responseMock.expects('send').once().withArgs('Hello World!'); hello(null, response); responseMock.verify(); }); });
  43. var sinon = require('sinon'); var hello = require('./app').hello; describe('hello', function()

    { it('should invoke `Response#send` with "Hello World!"', function() { var response = {send: function() {}}; var responseMock = sinon.mock(response); responseMock.expects('send').once().withArgs('Hello World!'); hello(null, response); responseMock.verify(); }); });
  44. var sinon = require('sinon'); var hello = require('./app').hello; describe('hello', function()

    { it('should invoke `Response#send` with "Hello World!"', function() { var response = {send: function() {}}; var responseMock = sinon.mock(response); responseMock.expects('send').once().withArgs('Hello World!'); hello(null, response); responseMock.verify(); }); });
  45. var sinon = require('sinon'); var hello = require('./app').hello; describe('hello', function()

    { it('should invoke `Response#send` with "Hello World!"', function() { var response = {send: function() {}}; var responseMock = sinon.mock(response); responseMock.expects('send').once().withArgs('Hello World!'); hello(null, response); responseMock.verify(); }); });
  46. var sinon = require('sinon'); var hello = require('./app').hello; describe('hello', function()

    { it('should invoke `Response#send` with "Hello World!"', function() { var response = {send: function() {}}; var responseMock = sinon.mock(response); responseMock.expects('send').once().withArgs('Hello World!'); hello(null, response); responseMock.verify(); }); });
  47. var sinon = require('sinon'); var hello = require('./app').hello; describe('hello', function()

    { it('should invoke `Response#send` with "Hello World!"', function() { var response = {send: function() {}}; var responseMock = sinon.mock(response); responseMock.expects('send').once().withArgs('Hello World!'); hello(null, response); responseMock.verify(); }); });
  48. var sinon = require('sinon'); var hello = require('./app').hello; describe('hello', function()

    { it('should invoke `Response#send` with "Hello World!"', function() { var response = {send: function() {}}; var responseMock = sinon.mock(response); responseMock.expects('send').once().withArgs('Hello World!'); hello(null, response); responseMock.verify(); }); });
  49. var sinon = require('sinon'); var hello = require('./app').hello; describe('hello', function()

    { it('should invoke `Response#send` with "Hello World!"', function() { var response = {send: function() {}}; var responseMock = sinon.mock(response); responseMock.expects('send').once().withArgs('Hello World!'); hello(null, response); responseMock.verify(); }); });
  50. var sinon = require('sinon'); var hello = require('./app').hello; describe('hello', function()

    { it('should invoke `Response#send` with "Hello World!"', function() { var response = {send: function() {}}; var responseMock = sinon.mock(response); responseMock.expects('send').once().withArgs('Hello World!'); hello(null, response); responseMock.verify(); }); });
  51. var sinon = require('sinon'); var hello = require('./app').hello; describe('hello', function()

    { it('should invoke `Response#send` with "Hello World!"', function() { var response = {send: function() {}}; var responseMock = sinon.mock(response); responseMock.expects('send').once().withArgs('Hello World!'); hello(null, response); responseMock.verify(); }); });
  52. var sinon = require('sinon'); var hello = require('./app').hello; describe('hello', function()

    { it('should invoke `Response#send` with "Hello World!"', function() { var response = {send: function() {}}; var responseMock = sinon.mock(response); responseMock.expects('send').once().withArgs('Hello World!'); hello(null, response); responseMock.verify(); }); });
  53. ➜ testing npm test > [email protected] test /home/joneshf/presentations/testing > mocha

    integration.js unit.js Routing to / ✓ should respond with "Hello World!" hello ✓ should invoke `Response#send` with "Hello World!" 2 passing (43ms)
  54. ➜ testing npm test > [email protected] test /home/joneshf/presentations/testing > mocha

    integration.js unit.js Routing to / ✓ should respond with "Hello World!" hello ✓ should invoke `Response#send` with "Hello World!" 2 passing (43ms)
  55. ➜ testing npm test > [email protected] test /home/joneshf/presentations/testing > mocha

    integration.js unit.js Routing to / ✓ should respond with "Hello World!" hello ✓ should invoke `Response#send` with "Hello World!" 2 passing (43ms)
  56. ➜ testing npm test > [email protected] test /home/joneshf/presentations/testing > mocha

    integration.js unit.js Routing to / ✓ should respond with "Hello World!" hello ✓ should invoke `Response#send` with "Hello World!" 2 passing (43ms)