SlideShare ist ein Scribd-Unternehmen logo
1 von 80
Downloaden Sie, um offline zu lesen
S Y S T E M AT I C U N I T
T E S T I N G
S C O T T G R A N T
A B O U T M E
• Scott Grant (hi!)
• Startup CTO in Kingston, Ontario
• Formerly @ Electronic Arts, Google
• Formerly Adjunct Prof. @ Queen's University
• Prof. James R. Cordy (CISC327: Software Quality
Assurance)
A B O U T M E G A M A N 2
• Developed and published by
Capcom in 1988 for the Nintendo
Entertainment System
• In 200X, Dr. Wily and his eight evil
Robot Masters threaten Mega Man,
Dr. Light, and the world
W H AT I S S Y S T E M AT I C
T E S T I N G ?
W H AT I S S Y S T E M AT I C T E S T I N G ?
• An explicit discipline or procedure (a system) for:
W H AT I S S Y S T E M AT I C T E S T I N G ?
• An explicit discipline or procedure (a system) for:
• choosing and creating test cases
W H AT I S S Y S T E M AT I C T E S T I N G ?
• An explicit discipline or procedure (a system) for:
• choosing and creating test cases
• executing the tests and documenting the results
W H AT I S S Y S T E M AT I C T E S T I N G ?
• An explicit discipline or procedure (a system) for:
• choosing and creating test cases
• executing the tests and documenting the results
• evaluating the results, possibly automatically
W H AT I S S Y S T E M AT I C T E S T I N G ?
• An explicit discipline or procedure (a system) for:
• choosing and creating test cases
• executing the tests and documenting the results
• evaluating the results, possibly automatically
• deciding when we are done (enough testing)
U N I T T E S T S
• Units are, preferably, the smallest testable part of an
application
• Unit tests are designed to test small pieces of the
code (units) independently
U N I T T E S T S
• Units are, preferably, the smallest testable part of an
application
• Unit tests are designed to test small pieces of the
code (units) independently
function sum( $a, $b ) {
return $a + $b;
}
U N I T T E S T S
• Units are, preferably, the smallest testable part of an
application
• Unit tests are designed to test small pieces of the
code (units) independently
function sum( $a, $b ) {
return $a + $b;
}
sum( 1, 1 ) == 2
U N I T T E S T S
• Units are, preferably, the smallest testable part of an
application
• Unit tests are designed to test small pieces of the
code (units) independently
function sum( $a, $b ) {
return $a + $b;
}
sum( 1, 1 ) == 2
$this->assertEquals( 2, sum( 1, 1 ) );
A S S E R T I O N S
• In many ways, the heart of a unit test
A S S E R T I O N S
• In many ways, the heart of a unit test
• Checks for a predefined constraint about the program
state
• "After sum is called with the arguments 1 and 1, it will
return the value 2."
A S S E R T I O N S
• In many ways, the heart of a unit test
• Checks for a predefined constraint about the program
state
• "After sum is called with the arguments 1 and 1, it will
return the value 2."
• If the constraint does not hold, the test fails
• The test asserts that the code is correct for a particular
context if the assertion holds
P H P U N I T
• Provides a framework for creating and executing unit
tests easily, quickly, and reproducibly
• Based on atomic unit tests with assertions
• Open-source!
• https://github.com/sebastianbergmann/phpunit
1 . C H O O S I N G A N D
C R E AT I N G T E S T C A S E S
W H AT M A K E S A G O O D T E S T ?
W H AT M A K E S A G O O D T E S T ?
• Independent: Each test needs to run independently
from other tests and environments
W H AT M A K E S A G O O D T E S T ?
• Independent: Each test needs to run independently
from other tests and environments
• Fast: To have useful tests and to be able to run them
as often as possible, tests need to be fast
W H AT M A K E S A G O O D T E S T ?
• Independent: Each test needs to run independently
from other tests and environments
• Fast: To have useful tests and to be able to run them
as often as possible, tests need to be fast
• Repeatable: You should be able to run a test as many
times as you want with the same result
W H AT M A K E S A G O O D T E S T ?
• Up to date: Tests are written once, but code can be
changed or extended
W H AT M A K E S A G O O D T E S T ?
• Up to date: Tests are written once, but code can be
changed or extended
• Short: Tests should be just a few lines--easy to read
and understand
W H AT M A K E S A G O O D T E S T ?
• Up to date: Tests are written once, but code can be
changed or extended
• Short: Tests should be just a few lines--easy to read
and understand
• Resilient: Once written, tests shouldn't change until
the behaviour of tested class/method changes
T E S T S I N I S O L AT I O N
T E S T S I N I S O L AT I O N
• Before each test, initialize the appropriate state
T E S T S I N I S O L AT I O N
• Before each test, initialize the appropriate state
• Next, perform the test
T E S T S I N I S O L AT I O N
• Before each test, initialize the appropriate state
• Next, perform the test
• One test! One!!
T E S T S I N I S O L AT I O N
• Before each test, initialize the appropriate state
• Next, perform the test
• One test! One!!
• After each test, clean up after yourself
T E S T S I N I S O L AT I O N
• Before each test, initialize the appropriate state
• Next, perform the test
• One test! One!!
• After each test, clean up after yourself
• There are more tests after this one, we don't want to
corrupt them with our test data
function is_even( $x ) {
if ( 0 == $x % 2 ) {
return true;
}
return false;
}
function is_odd( $x ) {
// ??
}
class Test_WCTO extends WP_UnitTestCase {
public function test_even_with_even() {
$this->assertTrue( is_even( 2 ) );
}
public function test_even_with_odd() {
$this->assertFalse( is_even( 1 ) );
}
}
C H O O S I N G & O R G A N I Z I N G T E S T S
• The experimental model of software testing gives us
two important principles for our test plan:
C H O O S I N G & O R G A N I Z I N G T E S T S
• The experimental model of software testing gives us
two important principles for our test plan:
• Test inputs should be chosen to carefully isolate
different causes of failure (the experimental
variables)
C H O O S I N G & O R G A N I Z I N G T E S T S
• The experimental model of software testing gives us
two important principles for our test plan:
• Test inputs should be chosen to carefully isolate
different causes of failure (the experimental
variables)
• Test cases should be ordered such that each test
only assumes features to be working that have
already been tested by a previous test
function is_odd( $x ) {
return ! is_even( $x );
}
function is_odd( $x ) {
$remainder = $x % 2;
if ( $remainder = 1 ) {
return true;
}
return false;
}
2 . E X E C U T I N G T H E T E S T S A N D
D O C U M E N T I N G T H E R E S U LT S
T E S T R E P O R T S
• Output of test execution should be summarized in a
readable report
T E S T R E P O R T S
• Output of test execution should be summarized in a
readable report
• Test reports should be designed to be concise, easy to
read, and to clearly point out failures or unexpectedly
changed results
T E S T R E P O R T S
• Output of test execution should be summarized in a
readable report
• Test reports should be designed to be concise, easy to
read, and to clearly point out failures or unexpectedly
changed results
• Test results should be in a standardized form for easy
comparison with future test executions
PHPUnit 4.5.0 by Sebastian Bergmann
and contributors.
Configuration read from /tmp/
wordpress/src/wp-content/plugins/two-
factor/phpunit.xml
.....................................
................
Time: 11.37 seconds, Memory: 71.50Mb
OK (53 tests, 90 assertions)
PHPUnit 4.4.0 by Sebastian Bergmann.
Configuration read from /home/travis/build/scotchfield/arcadia/
test/phpunit_travis.xml.dist
...............................................................
...............................................................
......................................................F........
....................................
Time: 2.52 seconds, Memory: 9.50Mb
There was 1 failure:
1) TestArcadiaUser::test_get_user_by_name_simple
Failed asserting that false is not false.
/home/travis/build/scotchfield/arcadia/test/tests/include/
test_user.php:43
FAILURES!
Tests: 225, Assertions: 292, Failures: 1.
3 . E VA L U AT I N G T H E R E S U LT S ,
P O S S I B LY A U T O M AT I C A L LY
T E S T R U N S U C C E S S
• When has a test run successfully completed?
T E S T R U N S U C C E S S
• When has a test run successfully completed?
• When all of the unit tests pass!
T E S T R U N S U C C E S S
• When has a test run successfully completed?
• When all of the unit tests pass!
• When does a unit test pass?
T E S T R U N S U C C E S S
• When has a test run successfully completed?
• When all of the unit tests pass!
• When does a unit test pass?
• When all of the assertions hold!
T E S T R U N S U C C E S S
• When has a test run successfully completed?
• When all of the unit tests pass!
• When does a unit test pass?
• When all of the assertions hold!
• When does an assertion hold?
T E S T R U N S U C C E S S
• When has a test run successfully completed?
• When all of the unit tests pass!
• When does a unit test pass?
• When all of the assertions hold!
• When does an assertion hold?
• When that individual piece of expected behaviour
captured in the assertion holds!
S A F E T Y B L A N K E T
• When a programmer makes a change to the code (any
change), they can run the test suite
S A F E T Y B L A N K E T
• When a programmer makes a change to the code (any
change), they can run the test suite
• If all of the tests pass, and we believe the test suite
covers enough functionality, we're fairly confident
that the code works
S A F E T Y B L A N K E T
• When a programmer makes a change to the code (any
change), they can run the test suite
• If all of the tests pass, and we believe the test suite
covers enough functionality, we're fairly confident
that the code works
• If a test fails, we might have broken something (or
exposed a bug!), and can fix it before checking in
http://cybermoonstudios.deviantart.com/art/Mega-Man-2-Robot-Masters-194915393
A U T O M AT E D T E S T I N G
• A continuous build machine can run unit tests after
every commit
A U T O M AT E D T E S T I N G
• A continuous build machine can run unit tests after
every commit
• Useful even if a programmer isn't proactively
running unit tests
A U T O M AT E D T E S T I N G
• A continuous build machine can run unit tests after
every commit
• Useful even if a programmer isn't proactively
running unit tests
• Catch bugs as they're introduced
A U T O M AT E D T E S T I N G
• A continuous build machine can run unit tests after
every commit
• Useful even if a programmer isn't proactively
running unit tests
• Catch bugs as they're introduced
• Or provide confidence that the code isn't going to
cause problems
4 . D E C I D I N G W H E N W E A R E
D O N E ( E N O U G H T E S T I N G )
W H E N A R E W E D O N E ?
• When we've achieved 100% code coverage
W H E N A R E W E D O N E ?
• When we've achieved 100% code coverage
• Not an ideal statistic
W H E N A R E W E D O N E ?
• When we've achieved 100% code coverage
• Not an ideal statistic
• Does not check for input, output, or functionality
coverage
W H E N A R E W E D O N E ?
• When we've achieved 100% code coverage
• Not an ideal statistic
• Does not check for input, output, or functionality
coverage
• Hard to achieve in practice
W H E N A R E W E D O N E ?
• When we've achieved 100% code coverage
• Not an ideal statistic
• Does not check for input, output, or functionality
coverage
• Hard to achieve in practice
• However, it's a clear and unambiguous goal
C O D E C O V E R A G E
• PHPUnit has a set of --coverage-* options
C O D E C O V E R A G E
• PHPUnit has a set of --coverage-* options
• Generate code coverage reports in various formats
C O D E C O V E R A G E
• PHPUnit has a set of --coverage-* options
• Generate code coverage reports in various formats
• Checks which lines of code are covered by at least
one unit test
C O D E C O V E R A G E
• PHPUnit has a set of --coverage-* options
• Generate code coverage reports in various formats
• Checks which lines of code are covered by at least
one unit test
• In addition, functions and classes
C O D E C O V E R A G E
• PHPUnit has a set of --coverage-* options
• Generate code coverage reports in various formats
• Checks which lines of code are covered by at least
one unit test
• In addition, functions and classes
• Does not check for input, output, or functionality
coverage
https://github.com/scotchfield/roller
https://github.com/scotchfield/roller
https://github.com/scotchfield/arcadia
https://github.com/scotchfield/arcadia
A systematic approach helps inform where new
tests are needed and provides one way to know
when a test suite is complete.
@ S C O T C H F I E L D
@ S G R A N T
S C O T T @ S C O O TA H . C O M

Weitere ähnliche Inhalte

Was ist angesagt?

Winning the battle against Automated testing
Winning the battle against Automated testingWinning the battle against Automated testing
Winning the battle against Automated testingElena Laskavaia
 
Bsides Knoxville - APT2
Bsides Knoxville - APT2Bsides Knoxville - APT2
Bsides Knoxville - APT2Adam Compton
 
Hack@macs 2014 test driven development & pair programing
Hack@macs 2014 test driven development & pair programingHack@macs 2014 test driven development & pair programing
Hack@macs 2014 test driven development & pair programingunihack
 
Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test PatternsFrank Appel
 
TestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the warTestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the warOleksiy Rezchykov
 
Unit testing (workshop)
Unit testing (workshop)Unit testing (workshop)
Unit testing (workshop)Foyzul Karim
 
Testing sync engine
Testing sync engineTesting sync engine
Testing sync engineIlya Puchka
 
Practical unit testing in c & c++
Practical unit testing in c & c++Practical unit testing in c & c++
Practical unit testing in c & c++Matt Hargett
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven DevelopmentPablo Villar
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And MockingJoe Wilson
 
Database development unit test with tSQLt
Database development unit test with tSQLtDatabase development unit test with tSQLt
Database development unit test with tSQLtSergio Govoni
 
Unit testing - the hard parts
Unit testing - the hard partsUnit testing - the hard parts
Unit testing - the hard partsShaun Abram
 
Practical (J)Unit Testing (2009)
Practical (J)Unit Testing (2009)Practical (J)Unit Testing (2009)
Practical (J)Unit Testing (2009)Peter Kofler
 
Implementing TDD in for .net Core applications
Implementing TDD in for .net Core applicationsImplementing TDD in for .net Core applications
Implementing TDD in for .net Core applicationsAhmad Kazemi
 
Automated Regression Testing for Embedded Systems in Action
Automated Regression Testing for Embedded Systems in ActionAutomated Regression Testing for Embedded Systems in Action
Automated Regression Testing for Embedded Systems in ActionAANDTech
 
How penetration testing techniques can help you improve your qa skills
How penetration testing techniques can help you improve your qa skillsHow penetration testing techniques can help you improve your qa skills
How penetration testing techniques can help you improve your qa skillsMarian Marinov
 
Tdd Ugialtnet Jan2010
Tdd Ugialtnet Jan2010Tdd Ugialtnet Jan2010
Tdd Ugialtnet Jan2010guestcff805
 
Getting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataCory Foy
 

Was ist angesagt? (20)

Winning the battle against Automated testing
Winning the battle against Automated testingWinning the battle against Automated testing
Winning the battle against Automated testing
 
Bsides Knoxville - APT2
Bsides Knoxville - APT2Bsides Knoxville - APT2
Bsides Knoxville - APT2
 
Hack@macs 2014 test driven development & pair programing
Hack@macs 2014 test driven development & pair programingHack@macs 2014 test driven development & pair programing
Hack@macs 2014 test driven development & pair programing
 
Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test Patterns
 
TestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the warTestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the war
 
Unit testing (workshop)
Unit testing (workshop)Unit testing (workshop)
Unit testing (workshop)
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Testing sync engine
Testing sync engineTesting sync engine
Testing sync engine
 
Practical unit testing in c & c++
Practical unit testing in c & c++Practical unit testing in c & c++
Practical unit testing in c & c++
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And Mocking
 
Database development unit test with tSQLt
Database development unit test with tSQLtDatabase development unit test with tSQLt
Database development unit test with tSQLt
 
Unit testing - the hard parts
Unit testing - the hard partsUnit testing - the hard parts
Unit testing - the hard parts
 
Practical (J)Unit Testing (2009)
Practical (J)Unit Testing (2009)Practical (J)Unit Testing (2009)
Practical (J)Unit Testing (2009)
 
Nunit
NunitNunit
Nunit
 
Implementing TDD in for .net Core applications
Implementing TDD in for .net Core applicationsImplementing TDD in for .net Core applications
Implementing TDD in for .net Core applications
 
Automated Regression Testing for Embedded Systems in Action
Automated Regression Testing for Embedded Systems in ActionAutomated Regression Testing for Embedded Systems in Action
Automated Regression Testing for Embedded Systems in Action
 
How penetration testing techniques can help you improve your qa skills
How penetration testing techniques can help you improve your qa skillsHow penetration testing techniques can help you improve your qa skills
How penetration testing techniques can help you improve your qa skills
 
Tdd Ugialtnet Jan2010
Tdd Ugialtnet Jan2010Tdd Ugialtnet Jan2010
Tdd Ugialtnet Jan2010
 
Getting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and Data
 

Andere mochten auch

Community Consultation Creates Compelling Content
Community Consultation Creates Compelling Content  Community Consultation Creates Compelling Content
Community Consultation Creates Compelling Content Christine Pollock
 
A Noob's Journey to the Core
A Noob's Journey to the CoreA Noob's Journey to the Core
A Noob's Journey to the CoreRyan Welcher
 
Using Actions and Filters in WordPress to Make a Plugin Your Own
Using Actions and Filters in WordPress to Make a Plugin Your OwnUsing Actions and Filters in WordPress to Make a Plugin Your Own
Using Actions and Filters in WordPress to Make a Plugin Your OwnBrian Hogg
 
Here Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPressHere Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPressRami Sayar
 
Help Me Help You: Practical Tips for Designers from A WordPress Developer
Help Me Help You: Practical Tips for Designers from A WordPress DeveloperHelp Me Help You: Practical Tips for Designers from A WordPress Developer
Help Me Help You: Practical Tips for Designers from A WordPress Developerdaraskolnick
 
You have 2 hands Toronto
You have 2 hands TorontoYou have 2 hands Toronto
You have 2 hands TorontoShayda Torabi
 
WordCamp Toronto 2015- API Simple Talk
WordCamp Toronto 2015- API Simple TalkWordCamp Toronto 2015- API Simple Talk
WordCamp Toronto 2015- API Simple Talkting-y
 
How I Made a Career Using WordPress Without Knowing a Line of Code
How I Made a Career Using WordPress Without Knowing a Line of CodeHow I Made a Career Using WordPress Without Knowing a Line of Code
How I Made a Career Using WordPress Without Knowing a Line of CodeAndrea Zoellner
 
Building and Maintaining A Remote Workforce - A Startup Story
Building and Maintaining A Remote Workforce - A Startup StoryBuilding and Maintaining A Remote Workforce - A Startup Story
Building and Maintaining A Remote Workforce - A Startup StorySucuri
 
Speeding up your WordPress Site - WordCamp Toronto 2015
Speeding up your WordPress Site - WordCamp Toronto 2015Speeding up your WordPress Site - WordCamp Toronto 2015
Speeding up your WordPress Site - WordCamp Toronto 2015Alan Lok
 
Writing Secure Code for WordPress
Writing Secure Code for WordPressWriting Secure Code for WordPress
Writing Secure Code for WordPressShawn Hooper
 
Best Friend || Worst Enemy: WordPress Multisite
Best Friend || Worst Enemy: WordPress MultisiteBest Friend || Worst Enemy: WordPress Multisite
Best Friend || Worst Enemy: WordPress MultisiteTaylor McCaslin
 
Delightful Design with the Kano Model (WordCamp Toronto 2015)
Delightful Design with the Kano Model (WordCamp Toronto 2015)Delightful Design with the Kano Model (WordCamp Toronto 2015)
Delightful Design with the Kano Model (WordCamp Toronto 2015)Jesse Emmanuel Rosario
 
How to use CSS3 in WordPress
How to use CSS3 in WordPressHow to use CSS3 in WordPress
How to use CSS3 in WordPressSuzette Franck
 
Multilingual content with WordPress
Multilingual content with WordPressMultilingual content with WordPress
Multilingual content with WordPressDesaulniers-Simard
 
Piecing Together the WordPress Puzzle
Piecing Together the WordPress PuzzlePiecing Together the WordPress Puzzle
Piecing Together the WordPress PuzzleBusiness Vitality LLC
 

Andere mochten auch (20)

Mystery solved pages vs posts
Mystery solved pages vs postsMystery solved pages vs posts
Mystery solved pages vs posts
 
Community Consultation Creates Compelling Content
Community Consultation Creates Compelling Content  Community Consultation Creates Compelling Content
Community Consultation Creates Compelling Content
 
A Noob's Journey to the Core
A Noob's Journey to the CoreA Noob's Journey to the Core
A Noob's Journey to the Core
 
Using Actions and Filters in WordPress to Make a Plugin Your Own
Using Actions and Filters in WordPress to Make a Plugin Your OwnUsing Actions and Filters in WordPress to Make a Plugin Your Own
Using Actions and Filters in WordPress to Make a Plugin Your Own
 
Here Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPressHere Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPress
 
Ecomm 101
Ecomm 101Ecomm 101
Ecomm 101
 
Wordcamp_mcglade_ux_mashups
Wordcamp_mcglade_ux_mashupsWordcamp_mcglade_ux_mashups
Wordcamp_mcglade_ux_mashups
 
Help Me Help You: Practical Tips for Designers from A WordPress Developer
Help Me Help You: Practical Tips for Designers from A WordPress DeveloperHelp Me Help You: Practical Tips for Designers from A WordPress Developer
Help Me Help You: Practical Tips for Designers from A WordPress Developer
 
You have 2 hands Toronto
You have 2 hands TorontoYou have 2 hands Toronto
You have 2 hands Toronto
 
WordCamp Toronto 2015- API Simple Talk
WordCamp Toronto 2015- API Simple TalkWordCamp Toronto 2015- API Simple Talk
WordCamp Toronto 2015- API Simple Talk
 
How I Made a Career Using WordPress Without Knowing a Line of Code
How I Made a Career Using WordPress Without Knowing a Line of CodeHow I Made a Career Using WordPress Without Knowing a Line of Code
How I Made a Career Using WordPress Without Knowing a Line of Code
 
Building and Maintaining A Remote Workforce - A Startup Story
Building and Maintaining A Remote Workforce - A Startup StoryBuilding and Maintaining A Remote Workforce - A Startup Story
Building and Maintaining A Remote Workforce - A Startup Story
 
Speeding up your WordPress Site - WordCamp Toronto 2015
Speeding up your WordPress Site - WordCamp Toronto 2015Speeding up your WordPress Site - WordCamp Toronto 2015
Speeding up your WordPress Site - WordCamp Toronto 2015
 
Writing Secure Code for WordPress
Writing Secure Code for WordPressWriting Secure Code for WordPress
Writing Secure Code for WordPress
 
Managed WordPress Demystified
Managed WordPress DemystifiedManaged WordPress Demystified
Managed WordPress Demystified
 
Best Friend || Worst Enemy: WordPress Multisite
Best Friend || Worst Enemy: WordPress MultisiteBest Friend || Worst Enemy: WordPress Multisite
Best Friend || Worst Enemy: WordPress Multisite
 
Delightful Design with the Kano Model (WordCamp Toronto 2015)
Delightful Design with the Kano Model (WordCamp Toronto 2015)Delightful Design with the Kano Model (WordCamp Toronto 2015)
Delightful Design with the Kano Model (WordCamp Toronto 2015)
 
How to use CSS3 in WordPress
How to use CSS3 in WordPressHow to use CSS3 in WordPress
How to use CSS3 in WordPress
 
Multilingual content with WordPress
Multilingual content with WordPressMultilingual content with WordPress
Multilingual content with WordPress
 
Piecing Together the WordPress Puzzle
Piecing Together the WordPress PuzzlePiecing Together the WordPress Puzzle
Piecing Together the WordPress Puzzle
 

Ähnlich wie Systematic Unit Testing

Testable JavaScript Strategies
Testable JavaScript StrategiesTestable JavaScript Strategies
Testable JavaScript StrategiesDiwa Del Mundo
 
Software engineering Testing technique,test case,test suit design
Software engineering Testing technique,test case,test suit designSoftware engineering Testing technique,test case,test suit design
Software engineering Testing technique,test case,test suit designMaitree Patel
 
Unit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step TrainingUnit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step TrainingRam Awadh Prasad, PMP
 
DSR Testing (Part 1)
DSR Testing (Part 1)DSR Testing (Part 1)
DSR Testing (Part 1)Steve Upton
 
Shift-Left Testing: QA in a DevOps World by David Laulusa
Shift-Left Testing: QA in a DevOps World by David LaulusaShift-Left Testing: QA in a DevOps World by David Laulusa
Shift-Left Testing: QA in a DevOps World by David LaulusaQA or the Highway
 
An Introduction to unit testing
An Introduction to unit testingAn Introduction to unit testing
An Introduction to unit testingSteven Casey
 
Module5 Testing and Verification.pdf
Module5 Testing and Verification.pdfModule5 Testing and Verification.pdf
Module5 Testing and Verification.pdfBhavanaHN5
 
Test automation principles, terminologies and implementations
Test automation principles, terminologies and implementationsTest automation principles, terminologies and implementations
Test automation principles, terminologies and implementationsSteven Li
 
Non equilibrium Molecular Simulations of Polymers under Flow Saving Energy th...
Non equilibrium Molecular Simulations of Polymers under Flow Saving Energy th...Non equilibrium Molecular Simulations of Polymers under Flow Saving Energy th...
Non equilibrium Molecular Simulations of Polymers under Flow Saving Energy th...ORAU
 
Generating unit tests based on user logs
Generating unit tests based on user logsGenerating unit tests based on user logs
Generating unit tests based on user logsRick Wicker
 
Software testing part
Software testing partSoftware testing part
Software testing partPreeti Mishra
 
DevDay 2016: Dave Farley - Acceptance testing for continuous delivery
DevDay 2016: Dave Farley - Acceptance testing for continuous deliveryDevDay 2016: Dave Farley - Acceptance testing for continuous delivery
DevDay 2016: Dave Farley - Acceptance testing for continuous deliveryDevDay Dresden
 
An Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitAn Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitweili_at_slideshare
 
FutureOfTesting2008
FutureOfTesting2008FutureOfTesting2008
FutureOfTesting2008vipulkocher
 
Finding Bugs Faster with Assertion Based Verification (ABV)
Finding Bugs Faster with Assertion Based Verification (ABV)Finding Bugs Faster with Assertion Based Verification (ABV)
Finding Bugs Faster with Assertion Based Verification (ABV)DVClub
 
Agile db testing_techniques
Agile db testing_techniquesAgile db testing_techniques
Agile db testing_techniquesTarik Essawi
 
utPLSQL: Unit Testing for Oracle PL/SQL
utPLSQL: Unit Testing for Oracle PL/SQLutPLSQL: Unit Testing for Oracle PL/SQL
utPLSQL: Unit Testing for Oracle PL/SQLSteven Feuerstein
 
How to become a testing expert
How to become a testing expertHow to become a testing expert
How to become a testing expertgaoliang641
 

Ähnlich wie Systematic Unit Testing (20)

Testable JavaScript Strategies
Testable JavaScript StrategiesTestable JavaScript Strategies
Testable JavaScript Strategies
 
Software engineering Testing technique,test case,test suit design
Software engineering Testing technique,test case,test suit designSoftware engineering Testing technique,test case,test suit design
Software engineering Testing technique,test case,test suit design
 
Unit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step TrainingUnit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step Training
 
DSR Testing (Part 1)
DSR Testing (Part 1)DSR Testing (Part 1)
DSR Testing (Part 1)
 
Shift-Left Testing: QA in a DevOps World by David Laulusa
Shift-Left Testing: QA in a DevOps World by David LaulusaShift-Left Testing: QA in a DevOps World by David Laulusa
Shift-Left Testing: QA in a DevOps World by David Laulusa
 
An Introduction to unit testing
An Introduction to unit testingAn Introduction to unit testing
An Introduction to unit testing
 
Module5 Testing and Verification.pdf
Module5 Testing and Verification.pdfModule5 Testing and Verification.pdf
Module5 Testing and Verification.pdf
 
Junit
JunitJunit
Junit
 
Test automation principles, terminologies and implementations
Test automation principles, terminologies and implementationsTest automation principles, terminologies and implementations
Test automation principles, terminologies and implementations
 
Non equilibrium Molecular Simulations of Polymers under Flow Saving Energy th...
Non equilibrium Molecular Simulations of Polymers under Flow Saving Energy th...Non equilibrium Molecular Simulations of Polymers under Flow Saving Energy th...
Non equilibrium Molecular Simulations of Polymers under Flow Saving Energy th...
 
Generating unit tests based on user logs
Generating unit tests based on user logsGenerating unit tests based on user logs
Generating unit tests based on user logs
 
Software testing part
Software testing partSoftware testing part
Software testing part
 
DevDay 2016: Dave Farley - Acceptance testing for continuous delivery
DevDay 2016: Dave Farley - Acceptance testing for continuous deliveryDevDay 2016: Dave Farley - Acceptance testing for continuous delivery
DevDay 2016: Dave Farley - Acceptance testing for continuous delivery
 
An Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnitAn Introduction to Unit Test Using NUnit
An Introduction to Unit Test Using NUnit
 
FutureOfTesting2008
FutureOfTesting2008FutureOfTesting2008
FutureOfTesting2008
 
Tdd
TddTdd
Tdd
 
Finding Bugs Faster with Assertion Based Verification (ABV)
Finding Bugs Faster with Assertion Based Verification (ABV)Finding Bugs Faster with Assertion Based Verification (ABV)
Finding Bugs Faster with Assertion Based Verification (ABV)
 
Agile db testing_techniques
Agile db testing_techniquesAgile db testing_techniques
Agile db testing_techniques
 
utPLSQL: Unit Testing for Oracle PL/SQL
utPLSQL: Unit Testing for Oracle PL/SQLutPLSQL: Unit Testing for Oracle PL/SQL
utPLSQL: Unit Testing for Oracle PL/SQL
 
How to become a testing expert
How to become a testing expertHow to become a testing expert
How to become a testing expert
 

Kürzlich hochgeladen

%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 

Kürzlich hochgeladen (20)

%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 

Systematic Unit Testing

  • 1. S Y S T E M AT I C U N I T T E S T I N G S C O T T G R A N T
  • 2.
  • 3. A B O U T M E • Scott Grant (hi!) • Startup CTO in Kingston, Ontario • Formerly @ Electronic Arts, Google • Formerly Adjunct Prof. @ Queen's University • Prof. James R. Cordy (CISC327: Software Quality Assurance)
  • 4. A B O U T M E G A M A N 2 • Developed and published by Capcom in 1988 for the Nintendo Entertainment System • In 200X, Dr. Wily and his eight evil Robot Masters threaten Mega Man, Dr. Light, and the world
  • 5. W H AT I S S Y S T E M AT I C T E S T I N G ?
  • 6. W H AT I S S Y S T E M AT I C T E S T I N G ? • An explicit discipline or procedure (a system) for:
  • 7. W H AT I S S Y S T E M AT I C T E S T I N G ? • An explicit discipline or procedure (a system) for: • choosing and creating test cases
  • 8. W H AT I S S Y S T E M AT I C T E S T I N G ? • An explicit discipline or procedure (a system) for: • choosing and creating test cases • executing the tests and documenting the results
  • 9. W H AT I S S Y S T E M AT I C T E S T I N G ? • An explicit discipline or procedure (a system) for: • choosing and creating test cases • executing the tests and documenting the results • evaluating the results, possibly automatically
  • 10. W H AT I S S Y S T E M AT I C T E S T I N G ? • An explicit discipline or procedure (a system) for: • choosing and creating test cases • executing the tests and documenting the results • evaluating the results, possibly automatically • deciding when we are done (enough testing)
  • 11. U N I T T E S T S • Units are, preferably, the smallest testable part of an application • Unit tests are designed to test small pieces of the code (units) independently
  • 12. U N I T T E S T S • Units are, preferably, the smallest testable part of an application • Unit tests are designed to test small pieces of the code (units) independently function sum( $a, $b ) { return $a + $b; }
  • 13. U N I T T E S T S • Units are, preferably, the smallest testable part of an application • Unit tests are designed to test small pieces of the code (units) independently function sum( $a, $b ) { return $a + $b; } sum( 1, 1 ) == 2
  • 14. U N I T T E S T S • Units are, preferably, the smallest testable part of an application • Unit tests are designed to test small pieces of the code (units) independently function sum( $a, $b ) { return $a + $b; } sum( 1, 1 ) == 2 $this->assertEquals( 2, sum( 1, 1 ) );
  • 15. A S S E R T I O N S • In many ways, the heart of a unit test
  • 16. A S S E R T I O N S • In many ways, the heart of a unit test • Checks for a predefined constraint about the program state • "After sum is called with the arguments 1 and 1, it will return the value 2."
  • 17. A S S E R T I O N S • In many ways, the heart of a unit test • Checks for a predefined constraint about the program state • "After sum is called with the arguments 1 and 1, it will return the value 2." • If the constraint does not hold, the test fails • The test asserts that the code is correct for a particular context if the assertion holds
  • 18. P H P U N I T • Provides a framework for creating and executing unit tests easily, quickly, and reproducibly • Based on atomic unit tests with assertions • Open-source! • https://github.com/sebastianbergmann/phpunit
  • 19. 1 . C H O O S I N G A N D C R E AT I N G T E S T C A S E S
  • 20. W H AT M A K E S A G O O D T E S T ?
  • 21. W H AT M A K E S A G O O D T E S T ? • Independent: Each test needs to run independently from other tests and environments
  • 22. W H AT M A K E S A G O O D T E S T ? • Independent: Each test needs to run independently from other tests and environments • Fast: To have useful tests and to be able to run them as often as possible, tests need to be fast
  • 23. W H AT M A K E S A G O O D T E S T ? • Independent: Each test needs to run independently from other tests and environments • Fast: To have useful tests and to be able to run them as often as possible, tests need to be fast • Repeatable: You should be able to run a test as many times as you want with the same result
  • 24. W H AT M A K E S A G O O D T E S T ? • Up to date: Tests are written once, but code can be changed or extended
  • 25. W H AT M A K E S A G O O D T E S T ? • Up to date: Tests are written once, but code can be changed or extended • Short: Tests should be just a few lines--easy to read and understand
  • 26. W H AT M A K E S A G O O D T E S T ? • Up to date: Tests are written once, but code can be changed or extended • Short: Tests should be just a few lines--easy to read and understand • Resilient: Once written, tests shouldn't change until the behaviour of tested class/method changes
  • 27.
  • 28. T E S T S I N I S O L AT I O N
  • 29. T E S T S I N I S O L AT I O N • Before each test, initialize the appropriate state
  • 30. T E S T S I N I S O L AT I O N • Before each test, initialize the appropriate state • Next, perform the test
  • 31. T E S T S I N I S O L AT I O N • Before each test, initialize the appropriate state • Next, perform the test • One test! One!!
  • 32. T E S T S I N I S O L AT I O N • Before each test, initialize the appropriate state • Next, perform the test • One test! One!! • After each test, clean up after yourself
  • 33. T E S T S I N I S O L AT I O N • Before each test, initialize the appropriate state • Next, perform the test • One test! One!! • After each test, clean up after yourself • There are more tests after this one, we don't want to corrupt them with our test data
  • 34. function is_even( $x ) { if ( 0 == $x % 2 ) { return true; } return false; } function is_odd( $x ) { // ?? }
  • 35. class Test_WCTO extends WP_UnitTestCase { public function test_even_with_even() { $this->assertTrue( is_even( 2 ) ); } public function test_even_with_odd() { $this->assertFalse( is_even( 1 ) ); } }
  • 36. C H O O S I N G & O R G A N I Z I N G T E S T S • The experimental model of software testing gives us two important principles for our test plan:
  • 37. C H O O S I N G & O R G A N I Z I N G T E S T S • The experimental model of software testing gives us two important principles for our test plan: • Test inputs should be chosen to carefully isolate different causes of failure (the experimental variables)
  • 38. C H O O S I N G & O R G A N I Z I N G T E S T S • The experimental model of software testing gives us two important principles for our test plan: • Test inputs should be chosen to carefully isolate different causes of failure (the experimental variables) • Test cases should be ordered such that each test only assumes features to be working that have already been tested by a previous test
  • 39. function is_odd( $x ) { return ! is_even( $x ); }
  • 40. function is_odd( $x ) { $remainder = $x % 2; if ( $remainder = 1 ) { return true; } return false; }
  • 41. 2 . E X E C U T I N G T H E T E S T S A N D D O C U M E N T I N G T H E R E S U LT S
  • 42. T E S T R E P O R T S • Output of test execution should be summarized in a readable report
  • 43. T E S T R E P O R T S • Output of test execution should be summarized in a readable report • Test reports should be designed to be concise, easy to read, and to clearly point out failures or unexpectedly changed results
  • 44. T E S T R E P O R T S • Output of test execution should be summarized in a readable report • Test reports should be designed to be concise, easy to read, and to clearly point out failures or unexpectedly changed results • Test results should be in a standardized form for easy comparison with future test executions
  • 45. PHPUnit 4.5.0 by Sebastian Bergmann and contributors. Configuration read from /tmp/ wordpress/src/wp-content/plugins/two- factor/phpunit.xml ..................................... ................ Time: 11.37 seconds, Memory: 71.50Mb OK (53 tests, 90 assertions)
  • 46. PHPUnit 4.4.0 by Sebastian Bergmann. Configuration read from /home/travis/build/scotchfield/arcadia/ test/phpunit_travis.xml.dist ............................................................... ............................................................... ......................................................F........ .................................... Time: 2.52 seconds, Memory: 9.50Mb There was 1 failure: 1) TestArcadiaUser::test_get_user_by_name_simple Failed asserting that false is not false. /home/travis/build/scotchfield/arcadia/test/tests/include/ test_user.php:43 FAILURES! Tests: 225, Assertions: 292, Failures: 1.
  • 47.
  • 48. 3 . E VA L U AT I N G T H E R E S U LT S , P O S S I B LY A U T O M AT I C A L LY
  • 49. T E S T R U N S U C C E S S • When has a test run successfully completed?
  • 50. T E S T R U N S U C C E S S • When has a test run successfully completed? • When all of the unit tests pass!
  • 51. T E S T R U N S U C C E S S • When has a test run successfully completed? • When all of the unit tests pass! • When does a unit test pass?
  • 52. T E S T R U N S U C C E S S • When has a test run successfully completed? • When all of the unit tests pass! • When does a unit test pass? • When all of the assertions hold!
  • 53. T E S T R U N S U C C E S S • When has a test run successfully completed? • When all of the unit tests pass! • When does a unit test pass? • When all of the assertions hold! • When does an assertion hold?
  • 54. T E S T R U N S U C C E S S • When has a test run successfully completed? • When all of the unit tests pass! • When does a unit test pass? • When all of the assertions hold! • When does an assertion hold? • When that individual piece of expected behaviour captured in the assertion holds!
  • 55. S A F E T Y B L A N K E T • When a programmer makes a change to the code (any change), they can run the test suite
  • 56. S A F E T Y B L A N K E T • When a programmer makes a change to the code (any change), they can run the test suite • If all of the tests pass, and we believe the test suite covers enough functionality, we're fairly confident that the code works
  • 57. S A F E T Y B L A N K E T • When a programmer makes a change to the code (any change), they can run the test suite • If all of the tests pass, and we believe the test suite covers enough functionality, we're fairly confident that the code works • If a test fails, we might have broken something (or exposed a bug!), and can fix it before checking in
  • 59. A U T O M AT E D T E S T I N G • A continuous build machine can run unit tests after every commit
  • 60. A U T O M AT E D T E S T I N G • A continuous build machine can run unit tests after every commit • Useful even if a programmer isn't proactively running unit tests
  • 61. A U T O M AT E D T E S T I N G • A continuous build machine can run unit tests after every commit • Useful even if a programmer isn't proactively running unit tests • Catch bugs as they're introduced
  • 62. A U T O M AT E D T E S T I N G • A continuous build machine can run unit tests after every commit • Useful even if a programmer isn't proactively running unit tests • Catch bugs as they're introduced • Or provide confidence that the code isn't going to cause problems
  • 63.
  • 64. 4 . D E C I D I N G W H E N W E A R E D O N E ( E N O U G H T E S T I N G )
  • 65. W H E N A R E W E D O N E ? • When we've achieved 100% code coverage
  • 66. W H E N A R E W E D O N E ? • When we've achieved 100% code coverage • Not an ideal statistic
  • 67. W H E N A R E W E D O N E ? • When we've achieved 100% code coverage • Not an ideal statistic • Does not check for input, output, or functionality coverage
  • 68. W H E N A R E W E D O N E ? • When we've achieved 100% code coverage • Not an ideal statistic • Does not check for input, output, or functionality coverage • Hard to achieve in practice
  • 69. W H E N A R E W E D O N E ? • When we've achieved 100% code coverage • Not an ideal statistic • Does not check for input, output, or functionality coverage • Hard to achieve in practice • However, it's a clear and unambiguous goal
  • 70. C O D E C O V E R A G E • PHPUnit has a set of --coverage-* options
  • 71. C O D E C O V E R A G E • PHPUnit has a set of --coverage-* options • Generate code coverage reports in various formats
  • 72. C O D E C O V E R A G E • PHPUnit has a set of --coverage-* options • Generate code coverage reports in various formats • Checks which lines of code are covered by at least one unit test
  • 73. C O D E C O V E R A G E • PHPUnit has a set of --coverage-* options • Generate code coverage reports in various formats • Checks which lines of code are covered by at least one unit test • In addition, functions and classes
  • 74. C O D E C O V E R A G E • PHPUnit has a set of --coverage-* options • Generate code coverage reports in various formats • Checks which lines of code are covered by at least one unit test • In addition, functions and classes • Does not check for input, output, or functionality coverage
  • 79.
  • 80. A systematic approach helps inform where new tests are needed and provides one way to know when a test suite is complete. @ S C O T C H F I E L D @ S G R A N T S C O T T @ S C O O TA H . C O M