SlideShare une entreprise Scribd logo
1  sur  35
Télécharger pour lire hors ligne
Release with
Confidence
INTEGRATION TEST AUTOMATION AND COVERAGE
FOR WEB SERVICE APPLICATIONS
About Me
 Currently CTO at a health tech start-up AristaMD
 Developing in PHP for ~14 years
 Author of Dialect (advanced PostgreSQL for
Eloquent) https://github.com/darrylkuhn/dialect
 I like to surf, scuba dive, travel, and read
 San Diego native
 The last movie I watched was “What we do in the
Shadows”
 I occasionally say something at:
 https://followingvannevar.wordpress.com/
 @darrylkuhn
Ground we’re going to
cover
 Quick intro to postman (calling web services)
 Quick intro to Jenkins (build automation)
 Test automation using postman/Jenkins
 Generating code coverage reports
 Some philosophy about test automation
This presentation utilizes Laravel 5 but nothing here is really
Laravel specific…
A simple service app
 We’re going to demo using a fictitious application
called fooblog.com
 Exposes a RESTful interface to
 Authenticate with a simple oAuth layer
 Get user data
 Manage Blog entries
Source at:
https://github.com/darrylkuhn/fooblog
…but before we get
started a little survey:
Survey:
 Who is familiar with the term API?
 What about REST or RESTful (who’s going to correct me
for using them interchangeably)?
 Who’s consumed a web service? Built web services?
 Who’s built unit tests? Who’s built integration tests?
 Who knows what code coverage is?
 Who’s using test automation now?
 Who’s ever pushed a change to a production and
crossed their fingers?
Postman
 API workflow tool (more @ getpostman.com)
 It’s FREE!
 Create requests quickly
 Replay and organize into Collections
 Switch context quickly with Environments
 Use JetPacks (a $10 add-on) to test responses with
simple JavaScript
 Use newman (free) to run tests (built in postman)
on the command line
Postman Interface
Collections
give you a
simple way to
organize your
web services,
and call them
over and over
Postman Interface
Environments
provide
variables
which make it
easy to switch
from test to
production
Postman Interface
Make GET,
POST, PUT,
DELETE, etc…
calls. Easily
include JSON,
XML, or plain
text payloads
Postman Interface
See your
responses
Postman Interface
Test your
responses with
simple
JavaScript
(using
Jetpacks). Set
elements in a
“tests” array to
capture test
results.
Let’s make some calls
Jenkins
 Build automation tool (more @ http://jenkins-ci.org/)
 It’s also FREE!
 Create “Jobs” which are just a series of actions to run in
sequence.
 Keeps a history of job runs, who ran them, what the result
was.
 Plugin architecture allows for a rich set of customizations.
Some of the stuff I use:
 Git Client (build from github source)
 Junit/CloverPHP (run unit tests and see coverage)
 Post-Build Script (deploy build artifacts)
 LDAP Plugin (centralize authentication)
Jenkins Interface
Push button
deployment
with progress
indicator
Jenkins Interface
Dashboard
overview of
current
coverage and
test results
Jenkins Interface
Get a history
of the jobs
you’ve
executed.
Who, what,
when. You get
a full change
history (if
integrated into
git) and shell
output.
Jenkins Interface
See code
coverage
(which tests
covered which
lines of code)
Let’s build a job
Jenkins/Postman
Coverage Recipe
1. Create a command to start / stop capturing
coverage
2. Add coverage capability to our app
3. Create a command to merge newman results
into our PHPUnit results
4. Configure Jenkins job to execute the test suite
and capture pass/fail and coverage details
+
But First…
Let’s quickly dive into sebastianbergmann/php-
code-coverage
+
php-code-coverage
project
 Authored by Sebastian Bergmann (PHPUnit
anyone?)
 Provides several classes that we’ll be using to store
and write coverage details including:
 PHP_CodeCoverage (this is the main class)
 PHP_CodeCoverage_Filter (only capture coverage
on specific files/directories)
 PHP_CodeCoverage_Report_Clover /
PHP_CodeCoverage_Report_HTML to output
coverage details in different formats
+
Step 1: Start/stop
capturing coverage
 Web Service calls take place over several PHP life-
cycles unlike PHPUnit (which runs in a single
master thread)
 We need to
 Identify at the start of the call’s lifecycle that code
execution should be covered
 Persist the captured coverage data somewhere
until we’re done with all requests
 Persistent storage engine: file (you can use
anything really – I use redis in the real world)
+
Let’s see some code
app/Console/Commands/TestCoverage.php
Step 2: Add coverage
capability to our app
 For Laravel that means adding a small piece of
Middleware to HTTP/Kernel.php
1. Check if we should be recording coverage
2. Pull any existing coverage from cache or create a
new coverage object
3. Register a shutdown function to save off the
coverage details when the process is complete
+
Let’s see some more code
app/Http/Middleware/Coverage.php
Step 3: Merge results
 Load PHPUnit XML
 Load Postman/Newman JSON
 Walk the JSON results adding each testsuite &
testcase to the XML result set
 Write the merged results
+
Step 3: Merge results
Full XSD at: https://windyroad.com.au/dl/Open%20Source/JUnit.xsd
<testsuites>
<testsuite name="Suite Name" tests="int" assertions="int" failures="int"
errors="int" time="seconds">
<testsuite name="Request Name" time="seconds" tests="int"
assertions="int" failures="int">
<testcase name="Test Name" time="seconds" />
</testsuite>
</testsuite>
</testsuites>
General Structure of the output:
"results": [
{
"name": "Request Name",
"totalTime": int (seconds),
"tests": {
"Test 1 Name": bool,
"Test 2 Name": bool
}
}
General Structure of the input:
+
Step 3: Merge results
 Load PHPUnit XML
 Load Postman/Newman JSON
 Walk the JSON results adding each testsuite &
testcase to the XML result set
 Write the merged results
+
Code please…
app/Console/Commands/MergeTestResults.php
Step 4: Create Jenkins job
 Add build action to
 Turn on coverage collection
 Run phpunit
 Run newman
 Write and merge test and coverage data
+
Let’s take a look under the hood…
Real life Jenkins example
 Build Script:
composer install
./artisan Testing:Coverage collect
vendor/bin/phpunit --log-junit results/phpunit/phpunit.xml -c phpunit.xml
mkdir -p results/newman/
newman -c postman/collection.json -e postman/build.json -o results/newman/build.json --
noColor
./artisan Testing:Coverage write
./artisan Testing:MergeResults
 Post-Build Script (success):
mkdir -p /var/builds/project/ #Make sure the path exists
cp -rpf ../workspace /var/builds/project/release_$BUILD_ID #Save artifacts
chmod -R g+w /var/builds/project/release_$BUILD_ID
chown -R :ops /var/builds/project/release_$BUILD_ID
rm -f /var/www/project #Remove symlink to old build
ln -s /var/builds/project/release_$BUILD_ID /var/www/project #Symlink new build
cd /var/www/project
./artisan migrate --force #Required for production environment
/var/lib/jenkins/jobs/project/sync.sh #Push build out to all servers
Scalability
In our production environment we have: 549 tests
across 111 requests
 On my Sandbox testing takes
 ~4 min 30 seconds with coverage
 ~1 min 30 seconds no coverage
 Coverage object reaches 3,350,401bytes (3.2MB)
 Writing coverage output
 Coverage XML: ~15 seconds
 Coverage HTML: ~10 seconds
Some philosophy about
test automation and
coverage
What is the purpose of test
automation?
I can change code with confidence
Some philosophy about
test automation and
coverage
Unit Tests v.s. Integration tests
Write unit tests to test your code, unit tests are for
developers
Write integration tests to test your application,
integration tests are for the business
Some philosophy about
test automation and
coverage
What does code coverage really get
you?
✓ I know where to focus my testing
✓ I know when I add lots of new code that isn’t tested
⃠ I know all my code works all the time
Some philosophy about
test automation and
coverage
How much coverage is “good”?
✓ 100% coverage doesn’t mean 100% perfect code
✓ Coverage establishes a baseline to manage to
✓ Worry about the things that matter – go after low hanging fruit
⃠ Don’t chase a number
Q&A
Thanks!

Contenu connexe

Tendances

Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Wim Godden
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.catPablo Godel
 
The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6Wim Godden
 
The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5Wim Godden
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slidesharetomcopeland
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryTatsuhiko Miyagawa
 
Laravel 4 package development
Laravel 4 package developmentLaravel 4 package development
Laravel 4 package developmentTihomir Opačić
 
The why and how of moving to php 5.4
The why and how of moving to php 5.4The why and how of moving to php 5.4
The why and how of moving to php 5.4Wim Godden
 
"Swoole: double troubles in c", Alexandr Vronskiy
"Swoole: double troubles in c", Alexandr Vronskiy"Swoole: double troubles in c", Alexandr Vronskiy
"Swoole: double troubles in c", Alexandr VronskiyFwdays
 
Static Typing in Vault
Static Typing in VaultStatic Typing in Vault
Static Typing in VaultGlynnForrest
 
PuppetConf 2017: Use Puppet to Tame the Dockerfile Monster- Bryan Belanger, A...
PuppetConf 2017: Use Puppet to Tame the Dockerfile Monster- Bryan Belanger, A...PuppetConf 2017: Use Puppet to Tame the Dockerfile Monster- Bryan Belanger, A...
PuppetConf 2017: Use Puppet to Tame the Dockerfile Monster- Bryan Belanger, A...Puppet
 
Beyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisBeyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisFastly
 
How to stay sane during your Vagrant journey
How to stay sane during your Vagrant journeyHow to stay sane during your Vagrant journey
How to stay sane during your Vagrant journeyJakub Wadolowski
 

Tendances (20)

Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011Caching and tuning fun for high scalability @ FrOSCon 2011
Caching and tuning fun for high scalability @ FrOSCon 2011
 
Laravel Day / Deploy
Laravel Day / DeployLaravel Day / Deploy
Laravel Day / Deploy
 
Intro to PSGI and Plack
Intro to PSGI and PlackIntro to PSGI and Plack
Intro to PSGI and Plack
 
Deploying Symfony | symfony.cat
Deploying Symfony | symfony.catDeploying Symfony | symfony.cat
Deploying Symfony | symfony.cat
 
The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6The why and how of moving to PHP 5.5/5.6
The why and how of moving to PHP 5.5/5.6
 
The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5The why and how of moving to PHP 5.4/5.5
The why and how of moving to PHP 5.4/5.5
 
Railsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshareRailsconf2011 deployment tips_for_slideshare
Railsconf2011 deployment tips_for_slideshare
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
 
Laravel 4 package development
Laravel 4 package developmentLaravel 4 package development
Laravel 4 package development
 
Getting testy with Perl
Getting testy with PerlGetting testy with Perl
Getting testy with Perl
 
Perlbal Tutorial
Perlbal TutorialPerlbal Tutorial
Perlbal Tutorial
 
The why and how of moving to php 5.4
The why and how of moving to php 5.4The why and how of moving to php 5.4
The why and how of moving to php 5.4
 
Plack - LPW 2009
Plack - LPW 2009Plack - LPW 2009
Plack - LPW 2009
 
Plack at YAPC::NA 2010
Plack at YAPC::NA 2010Plack at YAPC::NA 2010
Plack at YAPC::NA 2010
 
"Swoole: double troubles in c", Alexandr Vronskiy
"Swoole: double troubles in c", Alexandr Vronskiy"Swoole: double troubles in c", Alexandr Vronskiy
"Swoole: double troubles in c", Alexandr Vronskiy
 
Static Typing in Vault
Static Typing in VaultStatic Typing in Vault
Static Typing in Vault
 
PuppetConf 2017: Use Puppet to Tame the Dockerfile Monster- Bryan Belanger, A...
PuppetConf 2017: Use Puppet to Tame the Dockerfile Monster- Bryan Belanger, A...PuppetConf 2017: Use Puppet to Tame the Dockerfile Monster- Bryan Belanger, A...
PuppetConf 2017: Use Puppet to Tame the Dockerfile Monster- Bryan Belanger, A...
 
Beyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisBeyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic Analysis
 
Ruby HTTP clients
Ruby HTTP clientsRuby HTTP clients
Ruby HTTP clients
 
How to stay sane during your Vagrant journey
How to stay sane during your Vagrant journeyHow to stay sane during your Vagrant journey
How to stay sane during your Vagrant journey
 

Similaire à Release with confidence

RichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile DevicesRichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile DevicesPavol Pitoňák
 
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Ondřej Machulda
 
OSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshopOSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshopleffen
 
Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!Roberto Franchini
 
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)Fabrice Bernhard
 
Acceptance testing in php with Codeception - Techmeetup Edinburgh
Acceptance testing in php with Codeception - Techmeetup EdinburghAcceptance testing in php with Codeception - Techmeetup Edinburgh
Acceptance testing in php with Codeception - Techmeetup EdinburghEngineor
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShellBoulos Dib
 
AWS Lambda from the trenches
AWS Lambda from the trenchesAWS Lambda from the trenches
AWS Lambda from the trenchesYan Cui
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsDECK36
 
Continuous Integration using Cruise Control
Continuous Integration using Cruise ControlContinuous Integration using Cruise Control
Continuous Integration using Cruise Controlelliando dias
 
Turnkey Continuous Delivery
Turnkey Continuous DeliveryTurnkey Continuous Delivery
Turnkey Continuous DeliveryGianni Bombelli
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterHaehnchen
 
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)Bastian Feder
 
A Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy SystemA Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy Systemadrian_nye
 
Cloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
Cloud-powered Continuous Integration and Deployment architectures - Jinesh VariaCloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
Cloud-powered Continuous Integration and Deployment architectures - Jinesh VariaAmazon Web Services
 
Simple tools to fight bigger quality battle
Simple tools to fight bigger quality battleSimple tools to fight bigger quality battle
Simple tools to fight bigger quality battleAnand Ramdeo
 
AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...
AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...
AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...Amazon Web Services
 
Deployment Tactics
Deployment TacticsDeployment Tactics
Deployment TacticsIan Barber
 
Let's play with adf 3.0
Let's play with adf 3.0Let's play with adf 3.0
Let's play with adf 3.0Eugenio Romano
 

Similaire à Release with confidence (20)

RichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile DevicesRichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile Devices
 
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
 
OSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshopOSDC.no 2015 introduction to node.js workshop
OSDC.no 2015 introduction to node.js workshop
 
Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!Integration tests: use the containers, Luke!
Integration tests: use the containers, Luke!
 
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
 
Acceptance testing in php with Codeception - Techmeetup Edinburgh
Acceptance testing in php with Codeception - Techmeetup EdinburghAcceptance testing in php with Codeception - Techmeetup Edinburgh
Acceptance testing in php with Codeception - Techmeetup Edinburgh
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
 
AWS Lambda from the trenches
AWS Lambda from the trenchesAWS Lambda from the trenches
AWS Lambda from the trenches
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
 
Continuous Integration using Cruise Control
Continuous Integration using Cruise ControlContinuous Integration using Cruise Control
Continuous Integration using Cruise Control
 
Turnkey Continuous Delivery
Turnkey Continuous DeliveryTurnkey Continuous Delivery
Turnkey Continuous Delivery
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
 
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
 
A Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy SystemA Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy System
 
Cloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
Cloud-powered Continuous Integration and Deployment architectures - Jinesh VariaCloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
Cloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
 
Jenkins presentation
Jenkins presentationJenkins presentation
Jenkins presentation
 
Simple tools to fight bigger quality battle
Simple tools to fight bigger quality battleSimple tools to fight bigger quality battle
Simple tools to fight bigger quality battle
 
AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...
AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...
AWS December 2015 Webinar Series - Continuous Delivery to Amazon EC2 Containe...
 
Deployment Tactics
Deployment TacticsDeployment Tactics
Deployment Tactics
 
Let's play with adf 3.0
Let's play with adf 3.0Let's play with adf 3.0
Let's play with adf 3.0
 

Dernier

ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxNikitaBankoti2
 
Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Chameera Dedduwage
 
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024eCommerce Institute
 
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Delhi Call girls
 
Microsoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AIMicrosoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AITatiana Gurgel
 
Presentation on Engagement in Book Clubs
Presentation on Engagement in Book ClubsPresentation on Engagement in Book Clubs
Presentation on Engagement in Book Clubssamaasim06
 
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxMohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxmohammadalnahdi22
 
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort ServiceDelhi Call girls
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxraffaeleoman
 
Mathematics of Finance Presentation.pptx
Mathematics of Finance Presentation.pptxMathematics of Finance Presentation.pptx
Mathematics of Finance Presentation.pptxMoumonDas2
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...Sheetaleventcompany
 
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceDelhi Call girls
 
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Kayode Fayemi
 
SaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, YardstickSaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, Yardsticksaastr
 
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...Hasting Chen
 
Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Vipesco
 
Air breathing and respiratory adaptations in diver animals
Air breathing and respiratory adaptations in diver animalsAir breathing and respiratory adaptations in diver animals
Air breathing and respiratory adaptations in diver animalsaqsarehman5055
 
George Lever - eCommerce Day Chile 2024
George Lever -  eCommerce Day Chile 2024George Lever -  eCommerce Day Chile 2024
George Lever - eCommerce Day Chile 2024eCommerce Institute
 
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesVVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesPooja Nehwal
 
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdfThe workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdfSenaatti-kiinteistöt
 

Dernier (20)

ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
 
Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)
 
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
 
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
Night 7k Call Girls Noida Sector 128 Call Me: 8448380779
 
Microsoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AIMicrosoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AI
 
Presentation on Engagement in Book Clubs
Presentation on Engagement in Book ClubsPresentation on Engagement in Book Clubs
Presentation on Engagement in Book Clubs
 
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxMohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
 
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
 
Mathematics of Finance Presentation.pptx
Mathematics of Finance Presentation.pptxMathematics of Finance Presentation.pptx
Mathematics of Finance Presentation.pptx
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
 
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
 
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
 
SaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, YardstickSaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, Yardstick
 
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
 
Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510
 
Air breathing and respiratory adaptations in diver animals
Air breathing and respiratory adaptations in diver animalsAir breathing and respiratory adaptations in diver animals
Air breathing and respiratory adaptations in diver animals
 
George Lever - eCommerce Day Chile 2024
George Lever -  eCommerce Day Chile 2024George Lever -  eCommerce Day Chile 2024
George Lever - eCommerce Day Chile 2024
 
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesVVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
 
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdfThe workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
 

Release with confidence

  • 1. Release with Confidence INTEGRATION TEST AUTOMATION AND COVERAGE FOR WEB SERVICE APPLICATIONS
  • 2. About Me  Currently CTO at a health tech start-up AristaMD  Developing in PHP for ~14 years  Author of Dialect (advanced PostgreSQL for Eloquent) https://github.com/darrylkuhn/dialect  I like to surf, scuba dive, travel, and read  San Diego native  The last movie I watched was “What we do in the Shadows”  I occasionally say something at:  https://followingvannevar.wordpress.com/  @darrylkuhn
  • 3. Ground we’re going to cover  Quick intro to postman (calling web services)  Quick intro to Jenkins (build automation)  Test automation using postman/Jenkins  Generating code coverage reports  Some philosophy about test automation This presentation utilizes Laravel 5 but nothing here is really Laravel specific…
  • 4. A simple service app  We’re going to demo using a fictitious application called fooblog.com  Exposes a RESTful interface to  Authenticate with a simple oAuth layer  Get user data  Manage Blog entries Source at: https://github.com/darrylkuhn/fooblog
  • 5. …but before we get started a little survey: Survey:  Who is familiar with the term API?  What about REST or RESTful (who’s going to correct me for using them interchangeably)?  Who’s consumed a web service? Built web services?  Who’s built unit tests? Who’s built integration tests?  Who knows what code coverage is?  Who’s using test automation now?  Who’s ever pushed a change to a production and crossed their fingers?
  • 6. Postman  API workflow tool (more @ getpostman.com)  It’s FREE!  Create requests quickly  Replay and organize into Collections  Switch context quickly with Environments  Use JetPacks (a $10 add-on) to test responses with simple JavaScript  Use newman (free) to run tests (built in postman) on the command line
  • 7. Postman Interface Collections give you a simple way to organize your web services, and call them over and over
  • 8. Postman Interface Environments provide variables which make it easy to switch from test to production
  • 9. Postman Interface Make GET, POST, PUT, DELETE, etc… calls. Easily include JSON, XML, or plain text payloads
  • 11. Postman Interface Test your responses with simple JavaScript (using Jetpacks). Set elements in a “tests” array to capture test results.
  • 13. Jenkins  Build automation tool (more @ http://jenkins-ci.org/)  It’s also FREE!  Create “Jobs” which are just a series of actions to run in sequence.  Keeps a history of job runs, who ran them, what the result was.  Plugin architecture allows for a rich set of customizations. Some of the stuff I use:  Git Client (build from github source)  Junit/CloverPHP (run unit tests and see coverage)  Post-Build Script (deploy build artifacts)  LDAP Plugin (centralize authentication)
  • 16. Jenkins Interface Get a history of the jobs you’ve executed. Who, what, when. You get a full change history (if integrated into git) and shell output.
  • 17. Jenkins Interface See code coverage (which tests covered which lines of code)
  • 19. Jenkins/Postman Coverage Recipe 1. Create a command to start / stop capturing coverage 2. Add coverage capability to our app 3. Create a command to merge newman results into our PHPUnit results 4. Configure Jenkins job to execute the test suite and capture pass/fail and coverage details +
  • 20. But First… Let’s quickly dive into sebastianbergmann/php- code-coverage +
  • 21. php-code-coverage project  Authored by Sebastian Bergmann (PHPUnit anyone?)  Provides several classes that we’ll be using to store and write coverage details including:  PHP_CodeCoverage (this is the main class)  PHP_CodeCoverage_Filter (only capture coverage on specific files/directories)  PHP_CodeCoverage_Report_Clover / PHP_CodeCoverage_Report_HTML to output coverage details in different formats +
  • 22. Step 1: Start/stop capturing coverage  Web Service calls take place over several PHP life- cycles unlike PHPUnit (which runs in a single master thread)  We need to  Identify at the start of the call’s lifecycle that code execution should be covered  Persist the captured coverage data somewhere until we’re done with all requests  Persistent storage engine: file (you can use anything really – I use redis in the real world) + Let’s see some code app/Console/Commands/TestCoverage.php
  • 23. Step 2: Add coverage capability to our app  For Laravel that means adding a small piece of Middleware to HTTP/Kernel.php 1. Check if we should be recording coverage 2. Pull any existing coverage from cache or create a new coverage object 3. Register a shutdown function to save off the coverage details when the process is complete + Let’s see some more code app/Http/Middleware/Coverage.php
  • 24. Step 3: Merge results  Load PHPUnit XML  Load Postman/Newman JSON  Walk the JSON results adding each testsuite & testcase to the XML result set  Write the merged results +
  • 25. Step 3: Merge results Full XSD at: https://windyroad.com.au/dl/Open%20Source/JUnit.xsd <testsuites> <testsuite name="Suite Name" tests="int" assertions="int" failures="int" errors="int" time="seconds"> <testsuite name="Request Name" time="seconds" tests="int" assertions="int" failures="int"> <testcase name="Test Name" time="seconds" /> </testsuite> </testsuite> </testsuites> General Structure of the output: "results": [ { "name": "Request Name", "totalTime": int (seconds), "tests": { "Test 1 Name": bool, "Test 2 Name": bool } } General Structure of the input: +
  • 26. Step 3: Merge results  Load PHPUnit XML  Load Postman/Newman JSON  Walk the JSON results adding each testsuite & testcase to the XML result set  Write the merged results + Code please… app/Console/Commands/MergeTestResults.php
  • 27. Step 4: Create Jenkins job  Add build action to  Turn on coverage collection  Run phpunit  Run newman  Write and merge test and coverage data + Let’s take a look under the hood…
  • 28. Real life Jenkins example  Build Script: composer install ./artisan Testing:Coverage collect vendor/bin/phpunit --log-junit results/phpunit/phpunit.xml -c phpunit.xml mkdir -p results/newman/ newman -c postman/collection.json -e postman/build.json -o results/newman/build.json -- noColor ./artisan Testing:Coverage write ./artisan Testing:MergeResults  Post-Build Script (success): mkdir -p /var/builds/project/ #Make sure the path exists cp -rpf ../workspace /var/builds/project/release_$BUILD_ID #Save artifacts chmod -R g+w /var/builds/project/release_$BUILD_ID chown -R :ops /var/builds/project/release_$BUILD_ID rm -f /var/www/project #Remove symlink to old build ln -s /var/builds/project/release_$BUILD_ID /var/www/project #Symlink new build cd /var/www/project ./artisan migrate --force #Required for production environment /var/lib/jenkins/jobs/project/sync.sh #Push build out to all servers
  • 29. Scalability In our production environment we have: 549 tests across 111 requests  On my Sandbox testing takes  ~4 min 30 seconds with coverage  ~1 min 30 seconds no coverage  Coverage object reaches 3,350,401bytes (3.2MB)  Writing coverage output  Coverage XML: ~15 seconds  Coverage HTML: ~10 seconds
  • 30. Some philosophy about test automation and coverage What is the purpose of test automation? I can change code with confidence
  • 31. Some philosophy about test automation and coverage Unit Tests v.s. Integration tests Write unit tests to test your code, unit tests are for developers Write integration tests to test your application, integration tests are for the business
  • 32. Some philosophy about test automation and coverage What does code coverage really get you? ✓ I know where to focus my testing ✓ I know when I add lots of new code that isn’t tested ⃠ I know all my code works all the time
  • 33. Some philosophy about test automation and coverage How much coverage is “good”? ✓ 100% coverage doesn’t mean 100% perfect code ✓ Coverage establishes a baseline to manage to ✓ Worry about the things that matter – go after low hanging fruit ⃠ Don’t chase a number
  • 34. Q&A