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

JavaScript Testing and Continuous Integration

JavaScript Testing and Continuous Integration

jDays 2015

Mats Bryntse

March 18, 2015
Tweet

More Decks by Mats Bryntse

Other Decks in Technology

Transcript

  1. Agenda | Content Unit tests UI tests Continuous Integration •

    Writing a unit test • Using PhantomJS • Hello world sample • Testing a view • Recording a UI test • Application test • TeamCity • Code Coverage • Statistics • Cloud Testing
  2. Intro | WHY 1. Productivity & confidence in code 2.

    Frameworks contain bugs 3. So does your code (and mine) 4. Refactoring & code handover 5. Fix bugs once
  3. Intro | Unit Tests • should focus on a single

    JS class (“unit”) • should not involve DOM • is pure logic, runs very fast • is perfect for pre-commit hooks A unit test…
  4. Intro | Unit Tests describe('A simple Model test', function (t)

    {
 
 t.it('Should do something', function(t) { var user = new User({ name : ‘Bob’ });
 t.expect(user.name).toBe(‘Bob’);
 });
 });

  5. Intro | Unit Tests describe('A simple Model test', function (t)

    {
 t.it(‘Will not run', function(t) { … });
 
 t.iit(‘Isolate this section', function(t) { … });
 });

  6. Unit tests | Intro •Should be your #1 priority •Cover

    your most important JS classes, code that is reused •Run often, before commit, daily, nightly. •Use TDD approach + BDD style for readability
  7. Unit tests | TDD basics 1. Make the unit test

    fail 2. Implement 3. Make the test pass 4. Refactor, Repeat
  8. UI tests | Intro •UI “unit test” of a single

    UI component •Or Application test, open index.html and test it Two main types of UI tests
  9. Application tests | Intro •Black box testing, go to index.html…

    •Runs all the code of your application •Does app work or not?
  10. Application tests | Challenges •Database needs to be put in

    a known state pre test start •Slow •Fragile, race conditions •Errors likely harder to find
  11. Application tests | Event recorder •Great for application tests •Records

    user actions: clicks, types, drag drop •Can be used by a non-programmer •Big timesaver
  12. Application tests | Monkey tests •Random UI testing •Clicks, drags

    etc. in your UI •Finds unhandled exceptions •Free testing help. 0€
  13. Finding bugs | Pre-commit hook •Pre-commit hooks are great to

    keep code base clean •Check JsHint •Run unit tests
  14. Continuous Integration | Intro •Automated builds •Nightly test suite execution

    •Finding errors early => Code quality => Motivated developers •Enables Continuous Delivery Purpose of having CI:
  15. Continuous Integration | Intro •Bryntum uses TeamCity •Test suites run

    every 2 hours in Chrome •Full test suites executed nightly •Reports, statistics, charts and code coverage
  16. Continuous Integration | Cloud testing •Need to create Virtual Machines

    for each version of IE •Total: Chrome, Safari, FF, IE 7-11 => 8 VMs •Managing such a farm can be very time consuming
  17. Continuous Integration | Cloud testing •Siesta integrates with both BrowserStack

    and Sauce Labs •Run tests easily in any OS and Browser combination •No need to setup your own VM farm •Read more on the Bryntum blog…
  18. Rounding up | Summary •Prioritise JS unit tests •UI tests

    •Application & monkey tests •Tips for finding errors early •Continuous Integration
  19. Rounding up | Fika Dear Ladies and Gentlemen, 
 


    you are now welcome to ”Vinterträdgården” for a lovely coffee break that is sponsored by