SlideShare a Scribd company logo
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!

More Related Content

PDF
SDPHP - Percona Toolkit (It's Basically Magic)
Robert Swisher
 
PPT
How Danga::Socket handles asynchronous processing and how to write asynchrono...
Gosuke Miyashita
 
PDF
Ruby HTTP clients comparison
Hiroshi Nakamura
 
PDF
How to deploy node to production
Sean Hess
 
PPT
Assurer - a pluggable server testing/monitoring framework
Gosuke Miyashita
 
PDF
Shared Object images in Docker: What you need is what you want.
Workhorse Computing
 
PDF
Effective Benchmarks
Workhorse Computing
 
PDF
Unit Testing Lots of Perl
Workhorse Computing
 
SDPHP - Percona Toolkit (It's Basically Magic)
Robert Swisher
 
How Danga::Socket handles asynchronous processing and how to write asynchrono...
Gosuke Miyashita
 
Ruby HTTP clients comparison
Hiroshi Nakamura
 
How to deploy node to production
Sean Hess
 
Assurer - a pluggable server testing/monitoring framework
Gosuke Miyashita
 
Shared Object images in Docker: What you need is what you want.
Workhorse Computing
 
Effective Benchmarks
Workhorse Computing
 
Unit Testing Lots of Perl
Workhorse Computing
 

What's hot (20)

ODP
Caching and tuning fun for high scalability @ FrOSCon 2011
Wim Godden
 
PPTX
Laravel Day / Deploy
Simone Gentili
 
KEY
Intro to PSGI and Plack
Tatsuhiko Miyagawa
 
PDF
Deploying Symfony | symfony.cat
Pablo Godel
 
ODP
The why and how of moving to PHP 5.5/5.6
Wim Godden
 
ODP
The why and how of moving to PHP 5.4/5.5
Wim Godden
 
KEY
Railsconf2011 deployment tips_for_slideshare
tomcopeland
 
KEY
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Tatsuhiko Miyagawa
 
PDF
Laravel 4 package development
Tihomir Opačić
 
PDF
Getting testy with Perl
Workhorse Computing
 
PPT
Perlbal Tutorial
Takatsugu Shigeta
 
ODP
The why and how of moving to php 5.4
Wim Godden
 
KEY
Plack - LPW 2009
Tatsuhiko Miyagawa
 
KEY
Plack at YAPC::NA 2010
Tatsuhiko Miyagawa
 
PDF
"Swoole: double troubles in c", Alexandr Vronskiy
Fwdays
 
PDF
Static Typing in Vault
GlynnForrest
 
PPTX
PuppetConf 2017: Use Puppet to Tame the Dockerfile Monster- Bryan Belanger, A...
Puppet
 
PDF
Beyond Breakpoints: A Tour of Dynamic Analysis
Fastly
 
PDF
Ruby HTTP clients
Zoran Majstorovic
 
PDF
How to stay sane during your Vagrant journey
Jakub Wadolowski
 
Caching and tuning fun for high scalability @ FrOSCon 2011
Wim Godden
 
Laravel Day / Deploy
Simone Gentili
 
Intro to PSGI and Plack
Tatsuhiko Miyagawa
 
Deploying Symfony | symfony.cat
Pablo Godel
 
The why and how of moving to PHP 5.5/5.6
Wim Godden
 
The why and how of moving to PHP 5.4/5.5
Wim Godden
 
Railsconf2011 deployment tips_for_slideshare
tomcopeland
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Tatsuhiko Miyagawa
 
Laravel 4 package development
Tihomir Opačić
 
Getting testy with Perl
Workhorse Computing
 
Perlbal Tutorial
Takatsugu Shigeta
 
The why and how of moving to php 5.4
Wim Godden
 
Plack - LPW 2009
Tatsuhiko Miyagawa
 
Plack at YAPC::NA 2010
Tatsuhiko Miyagawa
 
"Swoole: double troubles in c", Alexandr Vronskiy
Fwdays
 
Static Typing in Vault
GlynnForrest
 
PuppetConf 2017: Use Puppet to Tame the Dockerfile Monster- Bryan Belanger, A...
Puppet
 
Beyond Breakpoints: A Tour of Dynamic Analysis
Fastly
 
Ruby HTTP clients
Zoran Majstorovic
 
How to stay sane during your Vagrant journey
Jakub Wadolowski
 
Ad

Similar to Release with confidence (20)

ODP
RichFaces - Testing on Mobile Devices
Pavol Pitoňák
 
PDF
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Ondřej Machulda
 
PDF
OSDC.no 2015 introduction to node.js workshop
leffen
 
PDF
Integration tests: use the containers, Luke!
Roberto Franchini
 
PDF
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Fabrice Bernhard
 
PDF
Acceptance testing in php with Codeception - Techmeetup Edinburgh
Engineor
 
PDF
Introduction to PowerShell
Boulos Dib
 
PDF
AWS Lambda from the trenches
Yan Cui
 
PDF
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
DECK36
 
PPT
Continuous Integration using Cruise Control
elliando dias
 
PDF
Turnkey Continuous Delivery
Gianni Bombelli
 
PDF
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Bastian Feder
 
PPTX
A Fabric/Puppet Build/Deploy System
adrian_nye
 
PPTX
Jenkins presentation
Valentin Buryakov
 
PPT
Simple tools to fight bigger quality battle
Anand Ramdeo
 
PDF
Deployment Tactics
Ian Barber
 
PPTX
Let's play with adf 3.0
Eugenio Romano
 
PDF
Zero Downtime Deployment with Ansible
Stein Inge Morisbak
 
PDF
Minimum Viable Docker: our journey towards orchestration
Outlyer
 
PDF
Continous Delivering a PHP application
Javier López
 
RichFaces - Testing on Mobile Devices
Pavol Pitoňák
 
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
Ondřej Machulda
 
OSDC.no 2015 introduction to node.js workshop
leffen
 
Integration tests: use the containers, Luke!
Roberto Franchini
 
Adopt DevOps philosophy on your Symfony projects (Symfony Live 2011)
Fabrice Bernhard
 
Acceptance testing in php with Codeception - Techmeetup Edinburgh
Engineor
 
Introduction to PowerShell
Boulos Dib
 
AWS Lambda from the trenches
Yan Cui
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
DECK36
 
Continuous Integration using Cruise Control
elliando dias
 
Turnkey Continuous Delivery
Gianni Bombelli
 
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Bastian Feder
 
A Fabric/Puppet Build/Deploy System
adrian_nye
 
Jenkins presentation
Valentin Buryakov
 
Simple tools to fight bigger quality battle
Anand Ramdeo
 
Deployment Tactics
Ian Barber
 
Let's play with adf 3.0
Eugenio Romano
 
Zero Downtime Deployment with Ansible
Stein Inge Morisbak
 
Minimum Viable Docker: our journey towards orchestration
Outlyer
 
Continous Delivering a PHP application
Javier López
 
Ad

Recently uploaded (20)

PPTX
Ocean_and_Freshwater_Awareness_Presentation.pptx
Suhaira9
 
PPTX
Mastering the DevOps Certification: CI/CD, Governance & Monitoring Made Simple
shubhamsharma994585
 
PPTX
Building a Strong and Ethical Digital Professional Identity
khalyaniramjan49
 
PPTX
Enterprise Asset Management Overview with examples
ManikantaBN1
 
PPTX
Bob Stewart Journey to Rome 07 30 2025.pptx
FamilyWorshipCenterD
 
PDF
Green Natural Green House Presentation (2).pdf
SaeedOsman6
 
PPTX
Rotary_Fundraising_Overview_Updated_new video .pptx
allangraemeduncan
 
PDF
Pesticides | Natural Pesticides | Methods of control | Types of pesticides | ...
Home
 
PDF
Something I m waiting to tell you By Shravya Bhinder
patelprushti2007
 
PDF
Chapter-52-Relationship-between-countries-at-different-levels-of-development-...
dinhminhthu1405
 
PDF
Helpful but Terrifying: Older Adults' Perspectives of AI in Remote Healthcare...
Daniela Napoli
 
PDF
Developing Accessible and Usable Security Heuristics
Daniela Napoli
 
PPTX
2025-07-27 Abraham 09 (shared slides).pptx
Dale Wells
 
PPTX
milgram study as level psychology core study (social approach)
dinhminhthu1405
 
PPTX
GAMABA AWARDEES GINAW BILOG AND SALINTA MONON BY REYMART
purezagambala458
 
PPTX
garment-industry in bangladesh. how bangladeshi industry is doing
tanvirhossain1570
 
PPTX
Introductions to artificial intelligence
rakshjain77
 
PPTX
Design Tips to Help Non-Visual Visitors Stay Safe Online
Daniela Napoli
 
PDF
Advanced-Web-Design-Crafting-the-Future-Web (1).pdf
vaghelavidhiba591
 
PPTX
Iconic Destinations in India: Explore Heritage and Beauty
dhorashankar
 
Ocean_and_Freshwater_Awareness_Presentation.pptx
Suhaira9
 
Mastering the DevOps Certification: CI/CD, Governance & Monitoring Made Simple
shubhamsharma994585
 
Building a Strong and Ethical Digital Professional Identity
khalyaniramjan49
 
Enterprise Asset Management Overview with examples
ManikantaBN1
 
Bob Stewart Journey to Rome 07 30 2025.pptx
FamilyWorshipCenterD
 
Green Natural Green House Presentation (2).pdf
SaeedOsman6
 
Rotary_Fundraising_Overview_Updated_new video .pptx
allangraemeduncan
 
Pesticides | Natural Pesticides | Methods of control | Types of pesticides | ...
Home
 
Something I m waiting to tell you By Shravya Bhinder
patelprushti2007
 
Chapter-52-Relationship-between-countries-at-different-levels-of-development-...
dinhminhthu1405
 
Helpful but Terrifying: Older Adults' Perspectives of AI in Remote Healthcare...
Daniela Napoli
 
Developing Accessible and Usable Security Heuristics
Daniela Napoli
 
2025-07-27 Abraham 09 (shared slides).pptx
Dale Wells
 
milgram study as level psychology core study (social approach)
dinhminhthu1405
 
GAMABA AWARDEES GINAW BILOG AND SALINTA MONON BY REYMART
purezagambala458
 
garment-industry in bangladesh. how bangladeshi industry is doing
tanvirhossain1570
 
Introductions to artificial intelligence
rakshjain77
 
Design Tips to Help Non-Visual Visitors Stay Safe Online
Daniela Napoli
 
Advanced-Web-Design-Crafting-the-Future-Web (1).pdf
vaghelavidhiba591
 
Iconic Destinations in India: Explore Heritage and Beauty
dhorashankar
 

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