SlideShare une entreprise Scribd logo
1  sur  11
Télécharger pour lire hors ligne
Perl Testing 101
Craig Treptow, August, 2013
Unit Tests
Goal
Isolate each part of a program and show that
the individual parts are correct.
Unit Tests
Benefits
● Find problems earlier
● Facilitate code changes
○ Help ensure changes did not affect other behavior

● Makes integration testing easier
● Code becomes “self documenting”
○ Just look at the tests
Unit Tests
Reality
● They do not “prove” software is correct
● They can be
○ wrong
○ hard to set up

● They do
○ increase programmer confidence
○ need to be treated like “real code”
Perl Testing
What is test code?
It’s just Perl code:
#!/usr/bin/perl -w

print "1..1n";

print 1 + 1 == 2 ? "ok 1n" : "not ok 1n";

Since 1 + 1 is 2, it prints:
1..1
ok 1
Perl Testing
1..1
ok 1

This says:
● I’m going to run 1 test
● The test passed
Perl Testing
Writing that kind of code would get tedious.
So, start with Test::Simple:
#!/usr/bin/perl -w

use Test::Simple tests => 1;

ok( 1 + 1 == 2 );

That runs the same test as before.
Perl Testing
Want more tests?
#!/usr/bin/perl -w

use Test::Simple tests => 2;
ok( 1 + 1 == 2 );
ok( 2 + 2 == 5 );

Run the test:
perl simple.t

Produces:
1..2
ok 1
not ok 2
#

Failed test (test.pl at line 5)

# Looks like you failed 1 tests of 2.
Perl Testing
Before we go on:
a few conventions
● Test files are kept in folders called ‘t’
● Test files are named <something>.t
○ 00-<test prerequisites>.t
○ 10-<module name>.t
○ 20-<module name>.t

There aren’t “rules”, it’s Perl!!
Perl Testing
Test::Simple
● Only provides ok()
● Can be awkward
○ Can’t tell what you got for a result
○ Only True/False (ok/not ok)

There is hope...
Perl Testing
Test::More
● ok(), is(), isnt()
● like(), unlike()
● cmp_ok(), can_ok(), isa_ok()
● use_ok(), require_ok()
● is_deeply()
● eq_array(), eq_hash(), eq_set

Contenu connexe

Tendances

Software engineering
Software engineeringSoftware engineering
Software engineering
bartlowe
 
PuppetConf 2017: Test Driving Your Infrastructure with Jesus Alvarez & Jesse ...
PuppetConf 2017: Test Driving Your Infrastructure with Jesus Alvarez & Jesse ...PuppetConf 2017: Test Driving Your Infrastructure with Jesus Alvarez & Jesse ...
PuppetConf 2017: Test Driving Your Infrastructure with Jesus Alvarez & Jesse ...
Puppet
 
javabasics_ programming development chapter01
javabasics_ programming development chapter01javabasics_ programming development chapter01
javabasics_ programming development chapter01
Udeshg90
 

Tendances (20)

PHPUnit with Magento
PHPUnit with MagentoPHPUnit with Magento
PHPUnit with Magento
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
Dot all 2019 | Testing with Craft | Giel Tettelar
Dot all 2019 | Testing with Craft | Giel TettelarDot all 2019 | Testing with Craft | Giel Tettelar
Dot all 2019 | Testing with Craft | Giel Tettelar
 
The art of being an agile programmer
The art of being an agile programmerThe art of being an agile programmer
The art of being an agile programmer
 
Test Driven Development Methodology and Philosophy
Test Driven Development Methodology and Philosophy Test Driven Development Methodology and Philosophy
Test Driven Development Methodology and Philosophy
 
Software engineering
Software engineeringSoftware engineering
Software engineering
 
Test Presentation
Test PresentationTest Presentation
Test Presentation
 
20150128 angular js_headless_testing
20150128 angular js_headless_testing20150128 angular js_headless_testing
20150128 angular js_headless_testing
 
TDD Basics with Angular.js and Jasmine
TDD Basics with Angular.js and JasmineTDD Basics with Angular.js and Jasmine
TDD Basics with Angular.js and Jasmine
 
Test Driven Development with PHPUnit
Test Driven Development with PHPUnitTest Driven Development with PHPUnit
Test Driven Development with PHPUnit
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
[FullStack NYC 2019] Effective Unit Tests for JavaScript
[FullStack NYC 2019] Effective Unit Tests for JavaScript[FullStack NYC 2019] Effective Unit Tests for JavaScript
[FullStack NYC 2019] Effective Unit Tests for JavaScript
 
TDD
TDDTDD
TDD
 
Btd presentation-2011
Btd presentation-2011Btd presentation-2011
Btd presentation-2011
 
DevOps
DevOpsDevOps
DevOps
 
PuppetConf 2017: Test Driving Your Infrastructure with Jesus Alvarez & Jesse ...
PuppetConf 2017: Test Driving Your Infrastructure with Jesus Alvarez & Jesse ...PuppetConf 2017: Test Driving Your Infrastructure with Jesus Alvarez & Jesse ...
PuppetConf 2017: Test Driving Your Infrastructure with Jesus Alvarez & Jesse ...
 
Agile testing for large projects
Agile testing for large projectsAgile testing for large projects
Agile testing for large projects
 
Android tdd
Android tddAndroid tdd
Android tdd
 
Top 25 Selenium Interview Questions and Answers 2018
Top 25 Selenium Interview Questions and Answers 2018Top 25 Selenium Interview Questions and Answers 2018
Top 25 Selenium Interview Questions and Answers 2018
 
javabasics_ programming development chapter01
javabasics_ programming development chapter01javabasics_ programming development chapter01
javabasics_ programming development chapter01
 

Similaire à Perl testing 101

Effective TDD - Less is more
Effective TDD - Less is moreEffective TDD - Less is more
Effective TDD - Less is more
Ben Lau
 

Similaire à Perl testing 101 (20)

Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Why unit testingl
Why unit testinglWhy unit testingl
Why unit testingl
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
utplsql.pdf
utplsql.pdfutplsql.pdf
utplsql.pdf
 
Tdd - introduction
Tdd - introductionTdd - introduction
Tdd - introduction
 
Getting started with unit and functional testing
Getting started with unit and functional testingGetting started with unit and functional testing
Getting started with unit and functional testing
 
What is Unit Testing
What is Unit TestingWhat is Unit Testing
What is Unit Testing
 
Project Onion unit test environment
Project Onion unit test environmentProject Onion unit test environment
Project Onion unit test environment
 
Unit testing
Unit testingUnit testing
Unit testing
 
Unit testing in PHP
Unit testing in PHPUnit testing in PHP
Unit testing in PHP
 
Software Testing Basic Concepts
Software Testing Basic ConceptsSoftware Testing Basic Concepts
Software Testing Basic Concepts
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017
 
Unit testing in PHP
Unit testing in PHPUnit testing in PHP
Unit testing in PHP
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
 
From Gatekeeper to Partner by Kelsey Shannahan
From Gatekeeper to Partner by Kelsey ShannahanFrom Gatekeeper to Partner by Kelsey Shannahan
From Gatekeeper to Partner by Kelsey Shannahan
 
Unit testing (eng)
Unit testing (eng)Unit testing (eng)
Unit testing (eng)
 
Effective TDD - Less is more
Effective TDD - Less is moreEffective TDD - Less is more
Effective TDD - Less is more
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
 

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@
 
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
 

Dernier (20)

+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...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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
 
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...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
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
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
"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 ...
 
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
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
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...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 

Perl testing 101

  • 1. Perl Testing 101 Craig Treptow, August, 2013
  • 2. Unit Tests Goal Isolate each part of a program and show that the individual parts are correct.
  • 3. Unit Tests Benefits ● Find problems earlier ● Facilitate code changes ○ Help ensure changes did not affect other behavior ● Makes integration testing easier ● Code becomes “self documenting” ○ Just look at the tests
  • 4. Unit Tests Reality ● They do not “prove” software is correct ● They can be ○ wrong ○ hard to set up ● They do ○ increase programmer confidence ○ need to be treated like “real code”
  • 5. Perl Testing What is test code? It’s just Perl code: #!/usr/bin/perl -w print "1..1n"; print 1 + 1 == 2 ? "ok 1n" : "not ok 1n"; Since 1 + 1 is 2, it prints: 1..1 ok 1
  • 6. Perl Testing 1..1 ok 1 This says: ● I’m going to run 1 test ● The test passed
  • 7. Perl Testing Writing that kind of code would get tedious. So, start with Test::Simple: #!/usr/bin/perl -w use Test::Simple tests => 1; ok( 1 + 1 == 2 ); That runs the same test as before.
  • 8. Perl Testing Want more tests? #!/usr/bin/perl -w use Test::Simple tests => 2; ok( 1 + 1 == 2 ); ok( 2 + 2 == 5 ); Run the test: perl simple.t Produces: 1..2 ok 1 not ok 2 # Failed test (test.pl at line 5) # Looks like you failed 1 tests of 2.
  • 9. Perl Testing Before we go on: a few conventions ● Test files are kept in folders called ‘t’ ● Test files are named <something>.t ○ 00-<test prerequisites>.t ○ 10-<module name>.t ○ 20-<module name>.t There aren’t “rules”, it’s Perl!!
  • 10. Perl Testing Test::Simple ● Only provides ok() ● Can be awkward ○ Can’t tell what you got for a result ○ Only True/False (ok/not ok) There is hope...
  • 11. Perl Testing Test::More ● ok(), is(), isnt() ● like(), unlike() ● cmp_ok(), can_ok(), isa_ok() ● use_ok(), require_ok() ● is_deeply() ● eq_array(), eq_hash(), eq_set