tests Smoke tests Test all the things! A Testing Pyramid for Node.js Microservices FrankfurtJS Meetup 5th of April, 2017 FrankfurtJS Meetup Test all the Things!
tests Smoke tests We write integration tests in a language agnostic way #readAppInfo.feature Feature: App information can be read Background: Given I set property request body to testdata app-info And I set the request header accept-version with value ~1 And I send a POST request to /devices/d123/apps/a123 Scenario: App information can be retrieved Given I set the request header accept-version with value ~1 When I send a GET request to /devices/d123/apps/a123 Then the response status code is 200 And I check property response body equals testdata app-info Scenario: Wrong url is used Given I set the request header accept-version with value ~1 And I send a GET request to /device/d123/app/a123 Then the response status code is 404 Scenario: Version not supported Given I set the request header accept-version with value ~999 And I send a GET request to /devices/d123/apps/a123 Then the response status code is 400 FrankfurtJS Meetup Test all the Things!
tests Smoke tests Custom test steps can be added if needed // steps.js const path = require('path') const config = require('../../../config') module.exports = function customSteps () { require('minosse').call(this) this.Before(function loadTestConfig (scenario, done) { // minosse checks for `testConfig` for framework configuration this.testConfig = { testDataRoot: path.join(__dirname, '../data') } done() }) this.Given(/^I set the test application to (\S+)$/, function changeApp (app, done) { this._log.info(`Step: I set the test application to ${app}`) this.testConfig.defaultHost = config.integrationTest.host this.testConfig.defaultPort = config.integrationTest[app].port done() }) } FrankfurtJS Meetup Test all the Things!
tests Smoke tests For end-2-end tests we use Minosse to hit the entrypoint of the system like the apps would do FrankfurtJS Meetup Test all the Things!
tests Smoke tests The docker-compose file for the E2E tests mimic the real system as close as possible some-nginx: build: context: ./somepath dockerfile: ./Dockerfile restart: always ports: - 80:80 consul: image: consul container_name: consul command: agent -server -client=0.0.0.0 -bind=0.0.0.0 -ui -bootstrap ports: - 8500:8500 registrator: image: gliderlabs/registrator container_name: registrator volumes: - /var/run/docker.sock:/tmp/docker.sock command: -internal consul://consul:8500 links: - consul syslog: build: somehost/syslogdummy container_name: syslog FrankfurtJS Meetup Test all the Things!
tests Smoke tests Running the whole system locally with docker-compose is a blessing Advantages Connect with mobile devices to the local PC Possible to plug in code for a specific shop to test it Edit different services and see the result immediately Catch configuration errors early on locally FrankfurtJS Meetup Test all the Things!
tests Smoke tests We run extensive smoke tests in all stages Smoke test deploys a whole new test shop container into the system Then runs DB-neutral test cases and removes the shop Swarm, consul etc. is utilized during deployment and problems can be catched Allows to catch AWS problems FrankfurtJS Meetup Test all the Things!
tests Smoke tests Links https://mochajs.org/ http://chaijs.com/ https://github.com/domenic/chai-as-promised http://sinonjs.org/ https://github.com/icemobilelab/minosse FrankfurtJS Meetup Test all the Things!