Automating JavaScript testing with Jasmine and Perl


Published on

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • First 1..1 is subtest that enclose it()1..4 within subtest are actual expect() statements“ok 1” finalizes subtest results“ok 6” finalizes describe()
  • Automating JavaScript testing with Jasmine and Perl

    1. 1. Automating JavaScript testing with Jasmine and Perl San talk Jun 21, 2012
    2. 2. Testing JavaScript: Why• The usual unit testing benefits, but also:• Improving browser compatibility• Catching regressions in your code• Catching browser regressions – very important!
    3. 3. Testing JavaScript: How• Many test frameworks out there, none of them as advanced and convenient as Test::Harness• All suffer from JavaScript restrictions on file system access, IO, etc.• Jasmine from Pivotal Labs is touted to be one of the best, which I think is true• But it’s also a pain to use: lots of boilerplate HTML just to run a spec, have to manage it all manually, etc.
    4. 4. Solution: Test::WWW::Jasmine• Take Jasmine test specs, run them in Selenium controlled browser• Generate all the boilerplate HTML and JavaScript required to run the specs• Parse Jasmine output, convert it to TAP• Each describe() is a test, each expect() is a subtest• Test diagnostic printed out with diag(), native to TAP::Harness
    5. 5. Example: Jasmine test spec/* * @css /css/css1.css * @script script1.js */describe(Test::WWW::Jasmine passing, function() { it(should run tests, function() { expect(true).toBeTruthy(); expect(false).toBeFalsy(); expect(undefined).toBeUndefined(); expect(null).toBeDefined() });});
    6. 6. Example: test output1..6ok 1 - use Test::WWW::Jasmine;ok 2 - Got objectok 3 - Right object isa Test::WWW::Jasmineok 4 - Parsed all css scriptsok 5 - Parsed all js scripts 1..1 ok 1 - expectation 1 ok 2 - expectation 2 ok 3 - expectation 3 ok 4 - expectation 4 1..4 ok 1 - should run testsok 6 - jasmine multiple test
    7. 7. Local testing• Automated testing is good, but it’d be cool if we could run the same specs locally while developing?• Enter jasmine.html: JavaScript/HTML spec runner that supports the same format as Test::WWW::Jasmine• Runs in browser locally, displays neat HTML (Jasmine default, actually)• Will be released soon, somewhere
    8. 8. Local testing: how results look like
    9. 9. Test::WWW::Jasmine warts• Work in progress, released to CPAN yesterday• Needs local (NFS anyone?) HTTP server with writable htdocs/something• Needs browser and Selenium installed• No headless testing yet (does it make sense?)• Maybe bundle jasmine.js along• Maybe run local tinyish HTTP server and serve specs off it
    10. 10. Questions? Ideas?• mine• Jasmine• Drop me an e-mail: