running-automated-tests-quickly



running-automated-tests-quickly

0 0


running-automated-tests-quickly


On Github travisj / running-automated-tests-quickly

Grunt + Jasmine

Getting faster feedback

from your tests

Travis Johnson / AppNexus

Started creating a Testing Culture about six months ago.

We had some tests, but it wasn't a given that tests would get written for new features.

Engineering@Scale: Building & Scaling a Test-Driven Culture

Daniel Doubrovkine (do-brove-kin)

Jenkins + Jasmine

Jenkins runs our unit tests on each check-in...

...but that is not fast enough.

The JavaScript Task Runner

grunt-contrib-jasmine

Install with:

$ npm install grunt-contrib-jasmine --save-dev

Enable in Gruntfile with:

grunt.loadNpmTasks('grunt-contrib-jasmine');

Gruntfile.js

module.exports = function(grunt) {
  grunt.initConfig({
    jasmine: {
      src: 'src/**/*.js',
      options: {
        specs: 'spec/**/*.js'
      }
    }
  });
  grunt.loadNpmTasks('grunt-contrib-jasmine');
  grunt.registerTask('test', ['jasmine']);
}

Run your tests

$ grunt test
Running "jasmine:examples" (jasmine) task
Testing jasmine specs via phantom
...
3 specs in 0.001s.
>> 0 failures

Done, without errors.

Nice, but...

I want to run these tests faster, easier, etc

Let's use Grunt to continuously run these for us.

grunt-regarde

Install with:

$ npm install grunt-regarde --save-dev

Enable in Gruntfile with:

grunt.loadNpmTasks('grunt-regarde');

Gruntfile.js

module.exports = function(grunt) {
  grunt.initConfig({
    jasmine: {...},
    regarde: {
      tests: {
        files: ['src/**', 'spec/**'],
        tasks: ['test']
      }
    },
  });

  grunt.loadNpmTasks('grunt-contrib-jasmine');
  grunt.loadNpmTasks('grunt-regarde');

  grunt.registerTask('test', ['jasmine']);
  grunt.registerTask('test-reload', ['test', 'regarde:tests']);
}

Run with:

$ grunt test-reload --force
Without --force, grunt will stop running on test failure.

--force is required due to an issue with regarde - will keep running tests on failure

grunt-notify

Install with:

$ npm install grunt-notify --save-dev

Enable in Gruntfile with:

grunt.loadNpmTasks('grunt-notify');

Resources

Contact me

Travis Johnson

tjohnson@appnexus.com