• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Automating JavaScript testing with Jasmine and Perl
 

Automating JavaScript testing with Jasmine and Perl

on

  • 1,981 views

 

Statistics

Views

Total Views
1,981
Views on SlideShare
976
Embed Views
1,005

Actions

Likes
1
Downloads
3
Comments
0

3 Embeds 1,005

http://nohuhu.org 1002
http://nohuhu.org. 2
http://hghltd.yandex.net 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • 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 Automating JavaScript testing with Jasmine and Perl Presentation Transcript

  • Automating JavaScript testing with Jasmine and Perl San Diego.pm talk Jun 21, 2012
  • Testing JavaScript: Why• The usual unit testing benefits, but also:• Improving browser compatibility• Catching regressions in your code• Catching browser regressions – very important!
  • 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.
  • 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
  • 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() });});
  • 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
  • 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
  • Local testing: how results look like
  • 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
  • Questions? Ideas?• http://metacpan.org/module/Test::WWW::Jas mine• http://github.com/nohuhu/Test-WWW- Jasmine• Drop me an e-mail: tokarev@cpan.org