SlideShare a Scribd company logo
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 output
1..6
ok 1 - use Test::WWW::Jasmine;
ok 2 - Got object
ok 3 - Right object isa Test::WWW::Jasmine
ok 4 - Parsed all css scripts
ok 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 tests
ok 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
Ad

Recommended

Developing Rich Internet Applications with Perl and JavaScript
Developing Rich Internet Applications with Perl and JavaScript
nohuhu
 
Proxying DBI with DBD::Gofer and App::Staticperl
Proxying DBI with DBD::Gofer and App::Staticperl
nohuhu
 
Why use Go for web development?
Why use Go for web development?
Weng Wei
 
Ci of js and apex using jasmine, phantom js and drone io df14
Ci of js and apex using jasmine, phantom js and drone io df14
Kevin Poorman
 
Hello world - intro to node js
Hello world - intro to node js
Refresh Annapolis Valley
 
Saving Time By Testing With Jest
Saving Time By Testing With Jest
Ben McCormick
 
Asynchronous Programming in Kotlin with Coroutines
Asynchronous Programming in Kotlin with Coroutines
Tobias Schürg
 
Next generation frontend tooling
Next generation frontend tooling
pksjce
 
Ruby, the language of devops
Ruby, the language of devops
Rob Kinyon
 
Scala vs ruby
Scala vs ruby
Kamil Lelonek
 
YAPC::EU 2015 - Perl Conferences
YAPC::EU 2015 - Perl Conferences
ℕicolas ℝ.
 
Functional Programming in PHP
Functional Programming in PHP
Aurimas Niekis
 
Python to go
Python to go
Weng Wei
 
КОСТЯНТИН КЛЮЄВ «Postman: API Automation Testing Swiss Army Knife» Kyiv QADay...
КОСТЯНТИН КЛЮЄВ «Postman: API Automation Testing Swiss Army Knife» Kyiv QADay...
QADay
 
About Clack
About Clack
fukamachi
 
Crystal
Crystal
Kamil Lelonek
 
PHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web Development
Irfan Maulana
 
Conquering AngularJS Limitations
Conquering AngularJS Limitations
Valeri Karpov
 
Angular4 kickstart
Angular4 kickstart
Foyzul Karim
 
Integration Testing with Selenium
Integration Testing with Selenium
All Things Open
 
Riak at Posterous
Riak at Posterous
capotej
 
Ruby performance - The low hanging fruit
Ruby performance - The low hanging fruit
Bruce Werdschinski
 
Unit Testing in JavaScript
Unit Testing in JavaScript
Rob Scaduto
 
Hands on Gradle
Hands on Gradle
Mushfekur Rahman
 
Cypress workshop for JSFoo 2019
Cypress workshop for JSFoo 2019
Biswajit Pattanayak
 
The Many Ways to Test Your React App
The Many Ways to Test Your React App
All Things Open
 
APIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page Objects
Sauce Labs
 
Ship It ! with Ruby/ Rails Ecosystem
Ship It ! with Ruby/ Rails Ecosystem
Yi-Ting Cheng
 
Testing sync engine
Testing sync engine
Ilya Puchka
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
Gil Fink
 

More Related Content

What's hot (20)

Ruby, the language of devops
Ruby, the language of devops
Rob Kinyon
 
Scala vs ruby
Scala vs ruby
Kamil Lelonek
 
YAPC::EU 2015 - Perl Conferences
YAPC::EU 2015 - Perl Conferences
ℕicolas ℝ.
 
Functional Programming in PHP
Functional Programming in PHP
Aurimas Niekis
 
Python to go
Python to go
Weng Wei
 
КОСТЯНТИН КЛЮЄВ «Postman: API Automation Testing Swiss Army Knife» Kyiv QADay...
КОСТЯНТИН КЛЮЄВ «Postman: API Automation Testing Swiss Army Knife» Kyiv QADay...
QADay
 
About Clack
About Clack
fukamachi
 
Crystal
Crystal
Kamil Lelonek
 
PHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web Development
Irfan Maulana
 
Conquering AngularJS Limitations
Conquering AngularJS Limitations
Valeri Karpov
 
Angular4 kickstart
Angular4 kickstart
Foyzul Karim
 
Integration Testing with Selenium
Integration Testing with Selenium
All Things Open
 
Riak at Posterous
Riak at Posterous
capotej
 
Ruby performance - The low hanging fruit
Ruby performance - The low hanging fruit
Bruce Werdschinski
 
Unit Testing in JavaScript
Unit Testing in JavaScript
Rob Scaduto
 
Hands on Gradle
Hands on Gradle
Mushfekur Rahman
 
Cypress workshop for JSFoo 2019
Cypress workshop for JSFoo 2019
Biswajit Pattanayak
 
The Many Ways to Test Your React App
The Many Ways to Test Your React App
All Things Open
 
APIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page Objects
Sauce Labs
 
Ship It ! with Ruby/ Rails Ecosystem
Ship It ! with Ruby/ Rails Ecosystem
Yi-Ting Cheng
 
Ruby, the language of devops
Ruby, the language of devops
Rob Kinyon
 
YAPC::EU 2015 - Perl Conferences
YAPC::EU 2015 - Perl Conferences
ℕicolas ℝ.
 
Functional Programming in PHP
Functional Programming in PHP
Aurimas Niekis
 
Python to go
Python to go
Weng Wei
 
КОСТЯНТИН КЛЮЄВ «Postman: API Automation Testing Swiss Army Knife» Kyiv QADay...
КОСТЯНТИН КЛЮЄВ «Postman: API Automation Testing Swiss Army Knife» Kyiv QADay...
QADay
 
PHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web Development
Irfan Maulana
 
Conquering AngularJS Limitations
Conquering AngularJS Limitations
Valeri Karpov
 
Angular4 kickstart
Angular4 kickstart
Foyzul Karim
 
Integration Testing with Selenium
Integration Testing with Selenium
All Things Open
 
Riak at Posterous
Riak at Posterous
capotej
 
Ruby performance - The low hanging fruit
Ruby performance - The low hanging fruit
Bruce Werdschinski
 
Unit Testing in JavaScript
Unit Testing in JavaScript
Rob Scaduto
 
The Many Ways to Test Your React App
The Many Ways to Test Your React App
All Things Open
 
APIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page Objects
Sauce Labs
 
Ship It ! with Ruby/ Rails Ecosystem
Ship It ! with Ruby/ Rails Ecosystem
Yi-Ting Cheng
 

Similar to Automating JavaScript testing with Jasmine and Perl (20)

Testing sync engine
Testing sync engine
Ilya Puchka
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
Gil Fink
 
Unit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma intro
Maurice De Beijer [MVP]
 
full-stack-webapp-testing-with-selenium-and-rails.pdf
full-stack-webapp-testing-with-selenium-and-rails.pdf
Brian Takita
 
Java script unit testing
Java script unit testing
Mats Bryntse
 
Selenium Tips & Tricks - StarWest 2015
Selenium Tips & Tricks - StarWest 2015
Andrew Krug
 
TDD super mondays-june-2014
TDD super mondays-june-2014
Alex Kavanagh
 
Jest: Frontend Testing leicht gemacht @EnterJS2018
Jest: Frontend Testing leicht gemacht @EnterJS2018
Holger Grosse-Plankermann
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Holger Grosse-Plankermann
 
Das Frontend richtig Testen – mit Jest @Developer Week 2018
Das Frontend richtig Testen – mit Jest @Developer Week 2018
Holger Grosse-Plankermann
 
Saving Time by Testing with Jest
Saving Time by Testing with Jest
All Things Open
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
Gil Fink
 
JavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and Karma
Christopher Bartling
 
How to use selenium successfully
How to use selenium successfully
TEST Huddle
 
Escaping Test Hell - ACCU 2014
Escaping Test Hell - ACCU 2014
Wojciech Seliga
 
Test::Kantan - Perl and Testing
Test::Kantan - Perl and Testing
Tokuhiro Matsuno
 
Jasmine presentation Selenium Camp 2013
Jasmine presentation Selenium Camp 2013
dimakovalenko
 
Automated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and Selenium
Dev9Com
 
Eureka Moment UKLUG
Eureka Moment UKLUG
Paul Withers
 
Automated Web Testing using JavaScript
Automated Web Testing using JavaScript
Simon Guest
 
Testing sync engine
Testing sync engine
Ilya Puchka
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
Gil Fink
 
Unit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma intro
Maurice De Beijer [MVP]
 
full-stack-webapp-testing-with-selenium-and-rails.pdf
full-stack-webapp-testing-with-selenium-and-rails.pdf
Brian Takita
 
Java script unit testing
Java script unit testing
Mats Bryntse
 
Selenium Tips & Tricks - StarWest 2015
Selenium Tips & Tricks - StarWest 2015
Andrew Krug
 
TDD super mondays-june-2014
TDD super mondays-june-2014
Alex Kavanagh
 
Jest: Frontend Testing leicht gemacht @EnterJS2018
Jest: Frontend Testing leicht gemacht @EnterJS2018
Holger Grosse-Plankermann
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Holger Grosse-Plankermann
 
Das Frontend richtig Testen – mit Jest @Developer Week 2018
Das Frontend richtig Testen – mit Jest @Developer Week 2018
Holger Grosse-Plankermann
 
Saving Time by Testing with Jest
Saving Time by Testing with Jest
All Things Open
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
Gil Fink
 
JavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and Karma
Christopher Bartling
 
How to use selenium successfully
How to use selenium successfully
TEST Huddle
 
Escaping Test Hell - ACCU 2014
Escaping Test Hell - ACCU 2014
Wojciech Seliga
 
Test::Kantan - Perl and Testing
Test::Kantan - Perl and Testing
Tokuhiro Matsuno
 
Jasmine presentation Selenium Camp 2013
Jasmine presentation Selenium Camp 2013
dimakovalenko
 
Automated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and Selenium
Dev9Com
 
Eureka Moment UKLUG
Eureka Moment UKLUG
Paul Withers
 
Automated Web Testing using JavaScript
Automated Web Testing using JavaScript
Simon Guest
 
Ad

Recently uploaded (20)

Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Impelsys Inc.
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Impelsys Inc.
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
Ad

Automating JavaScript testing with Jasmine and Perl

  • 1. Automating JavaScript testing with Jasmine and Perl San Diego.pm talk Jun 21, 2012
  • 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. 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. 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. 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. Example: test output 1..6 ok 1 - use Test::WWW::Jasmine; ok 2 - Got object ok 3 - Right object isa Test::WWW::Jasmine ok 4 - Parsed all css scripts ok 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 tests ok 6 - jasmine multiple test
  • 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. Local testing: how results look like
  • 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. Questions? Ideas? • http://metacpan.org/module/Test::WWW::Jas mine • http://github.com/nohuhu/Test-WWW- Jasmine • Drop me an e-mail: [email protected]

Editor's Notes

  • #7: 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()