SlideShare ist ein Scribd-Unternehmen logo
1 von 11
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie Perl testing 101

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

Ähnlich wie 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
 

Kürzlich hochgeladen

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
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
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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?
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

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