SlideShare une entreprise Scribd logo
1  sur  8
QUnit
         A
     JavaScript
Testing Framework
Outline
What Is QUnit?





Creating Tests with QUnit





References

What Is QUnit?


    QUnit is the testing suite for jQuery scripts and
    plugins.


    It doesn't need jQuery scripts to test other javascript
    codes.
Creating Tests with QUnit


    Download the QUnit script (and the optional QUnit
    css)


    Create test script to run against target external
    javascript


    Create html file to display test results
Sample Function to Test

function addNumbers(num1, num2) {
  if (isNaN(num1)) {
      return "First parameter is NaN";
  } else if (isNaN(num2)) {
      return "Second parameter is NaN";
  } else {
      return num1 + num2;
  }
}
Unit Test Script


test('addNumbers()', function() {
   equal(addNumbers(1,2), 3, 'using equal()');
})
The HTML File
<html>
<head>
    <title>QUnit Test Suite</title>
   <link rel="stylesheet" type="text/css" media="all"
href="qunit.css" />
    <script type="text/javascript" src="qunit.js"></script>
    <!-- Your project file goes here -->
    <script type="text/javascript" src="sourceScript.js"></script>

    <!-- Your tests file goes here -->
    <script type="text/javascript"
src="sourceScriptTest.js"></script>
</head>
<body>
    <h1 id="qunit-header">QUnit Test Suite for
sourceScript.js</h1>
    <h2 id="qunit-banner"></h2>
    <div id="qunit-testrunner-toolbar"></div>
    <h2 id="qunit-userAgent"></h2>
    <ol id="qunit-tests"></ol>
</body>
</html>
References

 net.tutsplus.com/tutorials/javascript-ajax/
how-to-test-your-javascript-code-with-qunit/

          docs.jquery.com/QUnit

Contenu connexe

En vedette

интересные факты из истории олимпийских игр1
интересные факты из истории олимпийских игр1интересные факты из истории олимпийских игр1
интересные факты из истории олимпийских игр1
Елена Денисова
 
嘔氣~不要跟你所在乎的人
嘔氣~不要跟你所在乎的人嘔氣~不要跟你所在乎的人
嘔氣~不要跟你所在乎的人
meihung06
 
Prepositions workshop
Prepositions workshopPrepositions workshop
Prepositions workshop
darkcrow08
 
Levin library databases page redesign
Levin library databases page redesignLevin library databases page redesign
Levin library databases page redesign
Emily Singley
 
Phm 1.1.5(Harman S. Gahir)
Phm 1.1.5(Harman S. Gahir)Phm 1.1.5(Harman S. Gahir)
Phm 1.1.5(Harman S. Gahir)
Harman Gahir
 

En vedette (18)

Derecho Privado
Derecho PrivadoDerecho Privado
Derecho Privado
 
Marketing Day - French Style or German Reliability - Alex Kowalczyk
Marketing Day - French Style or German Reliability - Alex KowalczykMarketing Day - French Style or German Reliability - Alex Kowalczyk
Marketing Day - French Style or German Reliability - Alex Kowalczyk
 
Raven
RavenRaven
Raven
 
Las_comunidades_de_práctica
Las_comunidades_de_prácticaLas_comunidades_de_práctica
Las_comunidades_de_práctica
 
Hoja de ruta jornada de inducción a madres y padres
Hoja de ruta jornada de inducción a madres y padresHoja de ruta jornada de inducción a madres y padres
Hoja de ruta jornada de inducción a madres y padres
 
интересные факты из истории олимпийских игр1
интересные факты из истории олимпийских игр1интересные факты из истории олимпийских игр1
интересные факты из истории олимпийских игр1
 
2011 (3) feb 1 15
2011 (3) feb 1 152011 (3) feb 1 15
2011 (3) feb 1 15
 
How Pokemon GO Can Drive Your Sales
How Pokemon GO Can Drive Your SalesHow Pokemon GO Can Drive Your Sales
How Pokemon GO Can Drive Your Sales
 
嘔氣~不要跟你所在乎的人
嘔氣~不要跟你所在乎的人嘔氣~不要跟你所在乎的人
嘔氣~不要跟你所在乎的人
 
Mannaclean| Protecting Assets, Improving Quality of Life
Mannaclean| Protecting Assets, Improving Quality of LifeMannaclean| Protecting Assets, Improving Quality of Life
Mannaclean| Protecting Assets, Improving Quality of Life
 
Cuerpo espacio y tiempo en propuesta docente
Cuerpo espacio y tiempo en propuesta docenteCuerpo espacio y tiempo en propuesta docente
Cuerpo espacio y tiempo en propuesta docente
 
How To Make Your Day Last Longer: Time Management in Marketing Projects
How To Make Your Day Last Longer: Time Management in Marketing Projects How To Make Your Day Last Longer: Time Management in Marketing Projects
How To Make Your Day Last Longer: Time Management in Marketing Projects
 
Prepositions workshop
Prepositions workshopPrepositions workshop
Prepositions workshop
 
Google App Engine - unusual application plaform for your next SaaS Project
Google App Engine - unusual application plaform for your next SaaS ProjectGoogle App Engine - unusual application plaform for your next SaaS Project
Google App Engine - unusual application plaform for your next SaaS Project
 
Levin library databases page redesign
Levin library databases page redesignLevin library databases page redesign
Levin library databases page redesign
 
Generosity during economic downturn
Generosity during economic downturnGenerosity during economic downturn
Generosity during economic downturn
 
La cigarra y la hormiga
La cigarra y la hormigaLa cigarra y la hormiga
La cigarra y la hormiga
 
Phm 1.1.5(Harman S. Gahir)
Phm 1.1.5(Harman S. Gahir)Phm 1.1.5(Harman S. Gahir)
Phm 1.1.5(Harman S. Gahir)
 

Plus de Exist

Plus de Exist (20)

Postgres Powers Digital Transformation in Southeast Asia – Success Stories
Postgres Powers Digital Transformation in Southeast Asia – Success StoriesPostgres Powers Digital Transformation in Southeast Asia – Success Stories
Postgres Powers Digital Transformation in Southeast Asia – Success Stories
 
Understanding Blockchain and Its Business Benefits
Understanding Blockchain and Its Business BenefitsUnderstanding Blockchain and Its Business Benefits
Understanding Blockchain and Its Business Benefits
 
ブロックチェーンのビジネス上の利点を理解する
ブロックチェーンのビジネス上の利点を理解するブロックチェーンのビジネス上の利点を理解する
ブロックチェーンのビジネス上の利点を理解する
 
How to Select the Right Automation Testing Tool
How to Select the Right Automation Testing ToolHow to Select the Right Automation Testing Tool
How to Select the Right Automation Testing Tool
 
Advancing Global Competitiveness Through Digital Transformation and Big Data ...
Advancing Global Competitiveness Through Digital Transformation and Big Data ...Advancing Global Competitiveness Through Digital Transformation and Big Data ...
Advancing Global Competitiveness Through Digital Transformation and Big Data ...
 
Exist Company Profile
Exist Company ProfileExist Company Profile
Exist Company Profile
 
Exist Company Profile (Nihongo)
Exist Company Profile (Nihongo)Exist Company Profile (Nihongo)
Exist Company Profile (Nihongo)
 
DX(デジタルトランスフォーメーション)とビッグデータでグローバル競争力強化を図ります
DX(デジタルトランスフォーメーション)とビッグデータでグローバル競争力強化を図りますDX(デジタルトランスフォーメーション)とビッグデータでグローバル競争力強化を図ります
DX(デジタルトランスフォーメーション)とビッグデータでグローバル競争力強化を図ります
 
Anahaw Retail Enterprise Solution
Anahaw Retail Enterprise SolutionAnahaw Retail Enterprise Solution
Anahaw Retail Enterprise Solution
 
Understanding the state of your web application using Apache Kafka, Spark
Understanding the state of your web application using Apache Kafka, SparkUnderstanding the state of your web application using Apache Kafka, Spark
Understanding the state of your web application using Apache Kafka, Spark
 
The Philippines eHealth Strategic Framework and Plan (Updates as of May 23, 2...
The Philippines eHealth Strategic Framework and Plan (Updates as of May 23, 2...The Philippines eHealth Strategic Framework and Plan (Updates as of May 23, 2...
The Philippines eHealth Strategic Framework and Plan (Updates as of May 23, 2...
 
API-Centric Rails Web Apps and Hybrid Mobile App Integration
API-Centric Rails Web Apps and Hybrid Mobile App IntegrationAPI-Centric Rails Web Apps and Hybrid Mobile App Integration
API-Centric Rails Web Apps and Hybrid Mobile App Integration
 
Clinical Analytics for Improving Health Outcomes
Clinical Analytics for Improving Health OutcomesClinical Analytics for Improving Health Outcomes
Clinical Analytics for Improving Health Outcomes
 
Exist Customer Success Stories
Exist Customer Success StoriesExist Customer Success Stories
Exist Customer Success Stories
 
Node.js Presentation
Node.js PresentationNode.js Presentation
Node.js Presentation
 
Selenium RC Using Java and Maven + Maestro Integration
Selenium RC Using Java and Maven + Maestro IntegrationSelenium RC Using Java and Maven + Maestro Integration
Selenium RC Using Java and Maven + Maestro Integration
 
Philippine Digital Strategy
Philippine Digital StrategyPhilippine Digital Strategy
Philippine Digital Strategy
 
Spectrum of IT BPO Services in the Philippines
Spectrum of IT BPO Services in the PhilippinesSpectrum of IT BPO Services in the Philippines
Spectrum of IT BPO Services in the Philippines
 
What's new in Drupal 7
What's new in Drupal 7What's new in Drupal 7
What's new in Drupal 7
 
Intro to jQuery
Intro to jQueryIntro to jQuery
Intro to jQuery
 

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Dernier (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
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
 
"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 ...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 

JavaScript Unit Testing Using QUnit

  • 1. QUnit A JavaScript Testing Framework
  • 2. Outline What Is QUnit?  Creating Tests with QUnit  References 
  • 3. What Is QUnit?  QUnit is the testing suite for jQuery scripts and plugins.  It doesn't need jQuery scripts to test other javascript codes.
  • 4. Creating Tests with QUnit  Download the QUnit script (and the optional QUnit css)  Create test script to run against target external javascript  Create html file to display test results
  • 5. Sample Function to Test function addNumbers(num1, num2) { if (isNaN(num1)) { return "First parameter is NaN"; } else if (isNaN(num2)) { return "Second parameter is NaN"; } else { return num1 + num2; } }
  • 6. Unit Test Script test('addNumbers()', function() { equal(addNumbers(1,2), 3, 'using equal()'); })
  • 7. The HTML File <html> <head> <title>QUnit Test Suite</title> <link rel="stylesheet" type="text/css" media="all" href="qunit.css" /> <script type="text/javascript" src="qunit.js"></script> <!-- Your project file goes here --> <script type="text/javascript" src="sourceScript.js"></script> <!-- Your tests file goes here --> <script type="text/javascript" src="sourceScriptTest.js"></script> </head> <body> <h1 id="qunit-header">QUnit Test Suite for sourceScript.js</h1> <h2 id="qunit-banner"></h2> <div id="qunit-testrunner-toolbar"></div> <h2 id="qunit-userAgent"></h2> <ol id="qunit-tests"></ol> </body> </html>