SlideShare ist ein Scribd-Unternehmen logo
1 von 10
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

Weitere ähnliche Inhalte

Was ist angesagt?

Python to go
Python to goPython to go
Python to go
Weng Wei
 

Was ist angesagt? (20)

Ruby, the language of devops
Ruby, the language of devopsRuby, the language of devops
Ruby, the language of devops
 
Scala vs ruby
Scala vs rubyScala vs ruby
Scala vs ruby
 
YAPC::EU 2015 - Perl Conferences
YAPC::EU 2015 - Perl ConferencesYAPC::EU 2015 - Perl Conferences
YAPC::EU 2015 - Perl Conferences
 
Functional Programming in PHP
Functional Programming in PHPFunctional Programming in PHP
Functional Programming in PHP
 
Python to go
Python to goPython to go
Python to go
 
КОСТЯНТИН КЛЮЄВ «Postman: API Automation Testing Swiss Army Knife» Kyiv QADay...
КОСТЯНТИН КЛЮЄВ «Postman: API Automation Testing Swiss Army Knife» Kyiv QADay...КОСТЯНТИН КЛЮЄВ «Postman: API Automation Testing Swiss Army Knife» Kyiv QADay...
КОСТЯНТИН КЛЮЄВ «Postman: API Automation Testing Swiss Army Knife» Kyiv QADay...
 
About Clack
About ClackAbout Clack
About Clack
 
Crystal
CrystalCrystal
Crystal
 
PHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web DevelopmentPHP Indonesia - Nodejs Web Development
PHP Indonesia - Nodejs Web Development
 
Conquering AngularJS Limitations
Conquering AngularJS LimitationsConquering AngularJS Limitations
Conquering AngularJS Limitations
 
Angular4 kickstart
Angular4 kickstartAngular4 kickstart
Angular4 kickstart
 
Integration Testing with Selenium
Integration Testing with SeleniumIntegration Testing with Selenium
Integration Testing with Selenium
 
Riak at Posterous
Riak at PosterousRiak at Posterous
Riak at Posterous
 
Ruby performance - The low hanging fruit
Ruby performance - The low hanging fruitRuby performance - The low hanging fruit
Ruby performance - The low hanging fruit
 
Unit Testing in JavaScript
Unit Testing in JavaScriptUnit Testing in JavaScript
Unit Testing in JavaScript
 
Hands on Gradle
Hands on GradleHands on Gradle
Hands on Gradle
 
Cypress workshop for JSFoo 2019
Cypress  workshop for JSFoo 2019Cypress  workshop for JSFoo 2019
Cypress workshop for JSFoo 2019
 
The Many Ways to Test Your React App
The Many Ways to Test Your React AppThe Many Ways to Test Your React App
The Many Ways to Test Your React App
 
APIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page ObjectsAPIs: A Better Alternative to Page Objects
APIs: A Better Alternative to Page Objects
 
Ship It ! with Ruby/ Rails Ecosystem
Ship It ! with Ruby/ Rails EcosystemShip It ! with Ruby/ Rails Ecosystem
Ship It ! with Ruby/ Rails Ecosystem
 

Ähnlich wie Automating JavaScript testing with Jasmine and Perl

Ähnlich wie Automating JavaScript testing with Jasmine and Perl (20)

Testing sync engine
Testing sync engineTesting sync engine
Testing sync engine
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
 
Unit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma introUnit testing JavaScript: Jasmine & karma intro
Unit testing JavaScript: Jasmine & karma intro
 
full-stack-webapp-testing-with-selenium-and-rails.pdf
full-stack-webapp-testing-with-selenium-and-rails.pdffull-stack-webapp-testing-with-selenium-and-rails.pdf
full-stack-webapp-testing-with-selenium-and-rails.pdf
 
Java script unit testing
Java script unit testingJava script unit testing
Java script unit testing
 
Selenium Tips & Tricks - StarWest 2015
Selenium Tips & Tricks - StarWest 2015Selenium Tips & Tricks - StarWest 2015
Selenium Tips & Tricks - StarWest 2015
 
TDD super mondays-june-2014
TDD super mondays-june-2014TDD super mondays-june-2014
TDD super mondays-june-2014
 
Jest: Frontend Testing leicht gemacht @EnterJS2018
Jest: Frontend Testing leicht gemacht @EnterJS2018Jest: Frontend Testing leicht gemacht @EnterJS2018
Jest: Frontend Testing leicht gemacht @EnterJS2018
 
Jest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRWJest: Frontend Testing richtig gemacht @WebworkerNRW
Jest: Frontend Testing richtig gemacht @WebworkerNRW
 
Das Frontend richtig Testen – mit Jest @Developer Week 2018
Das Frontend richtig Testen – mit Jest @Developer Week 2018Das Frontend richtig Testen – mit Jest @Developer Week 2018
Das Frontend richtig Testen – mit Jest @Developer Week 2018
 
Saving Time by Testing with Jest
Saving Time by Testing with JestSaving Time by Testing with Jest
Saving Time by Testing with Jest
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
 
JavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and KarmaJavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and Karma
 
How to use selenium successfully
How to use selenium successfullyHow to use selenium successfully
How to use selenium successfully
 
Escaping Test Hell - ACCU 2014
Escaping Test Hell - ACCU 2014Escaping Test Hell - ACCU 2014
Escaping Test Hell - ACCU 2014
 
Test::Kantan - Perl and Testing
Test::Kantan - Perl and TestingTest::Kantan - Perl and Testing
Test::Kantan - Perl and Testing
 
Jasmine presentation Selenium Camp 2013
Jasmine presentation Selenium Camp 2013Jasmine presentation Selenium Camp 2013
Jasmine presentation Selenium Camp 2013
 
Automated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and SeleniumAutomated Testing with Cucumber, PhantomJS and Selenium
Automated Testing with Cucumber, PhantomJS and Selenium
 
Eureka Moment UKLUG
Eureka Moment UKLUGEureka Moment UKLUG
Eureka Moment UKLUG
 
Automated Web Testing using JavaScript
Automated Web Testing using JavaScriptAutomated Web Testing using JavaScript
Automated Web Testing using JavaScript
 

Kürzlich hochgeladen

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 

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: tokarev@cpan.org

Hinweis der Redaktion

  1. 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()