using docker for testing

28
Using Docker for Testing MUKTA APHALE ATA GTR 2016, PUNE @muktaa

Upload: mukta-aphale

Post on 16-Apr-2017

862 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Using Docker for Testing

Using Docker for TestingMUKTA APHALE

ATA GTR 2016, PUNE

@muktaa

Page 2: Using Docker for Testing

Who Am I?• Developer, DevOps Enthusiast• Passion for technology, innovation and the thirst to keep

learning• Love to code• Love to design solutions• Love to network• Believe in dreaming big• Believe in work-life balance

@muktaa

Page 3: Using Docker for Testing

Agenda•Where testing stands today, current challenges of

testing•What is Docker?•How can docker help in better automation testing?•A traditional way of doing integration testing•Demo of using Docker for testing•Demo of integrating dockerized tests with your CI

@muktaa

Page 4: Using Docker for Testing

Pain Points of Testing•Unit tests, integration tests, complex integration tests•UI testing•Git branching• Environments• Failed tests pollute environment•Deployment dependencies, testing dependencies

@muktaa

Page 5: Using Docker for Testing

Docker

@muktaa

Linux  Container Docker Data  Centre,  Docker Cloud,  DockerEngine,  Docker Hub,  

UCP

Benefits:Speed

PortabilityDensity

Open  Source

“Can  create  lightweight,  self  sufficient  containers  from  

any  application”

Page 6: Using Docker for Testing

Docker Applications•Testing•Microservices Applications• Simplifying Development• Simplifying Deployment•Production• CaaS

@muktaa

Page 7: Using Docker for Testing

Docker for enabling Testing•Mimic production environment• Consistent Environments•Black Box Testing• Scalability Testing• Configuration Testing•Testing Simplified

@muktaa

Page 8: Using Docker for Testing

Deploying for Integration Testing: Old Way• Build project• SCP the build artifact to the

server(s)• Ssh into the server• Stop webserver• Replace the build artifact at the

right path• Restart webserver

o SCP the tar.gz from the project to the server(s)

o ssh into the servero stop tomcato remove the “work”, “webapps”,

“shared” and “common” folderso extract the tar.gz into the

tomcat foldero start tomcat

@muktaa

Page 9: Using Docker for Testing

Integration Testing: Old Way•Wait for deployment to complete◦Webserver comes up

• Ensure setup is clean◦DB Scripts, Env variables, etc

•Get your latest integration test code ready•Point your integration tests to your newly deployed

setup•Run integration tests

@muktaa

Page 10: Using Docker for Testing

Let’s use Docker…

@muktaa

Page 11: Using Docker for Testing

Example Scenario• Webserver

• NGiNX

• App Server• 3 load balanced instances• Node js

• DB Server• Redis

@muktaa

Page 12: Using Docker for Testing

Output• Prints the number of times

the page was hit

• Source Code:

https://github.com/muktaa/docker-example/

@muktaa

Page 13: Using Docker for Testing

Dockerizing Each Component• Dockerfile for each

component• Docker-compose.yml• Build Script

@muktaa

Page 14: Using Docker for Testing

DemoDEPLOY APPLICATION FOR INTEGRATION TESTING

@muktaa

Page 15: Using Docker for Testing

Steps•Git clone https://github.com/muktaa/docker-example/•Docker-compose build•Docker-compose up

@muktaa

Page 16: Using Docker for Testing

Running Integration TestsLETS DOCKERIZE THE INTEGRATION TESTS TOO!

@muktaa

Page 17: Using Docker for Testing

Example of Selenium Tests• https://github.com/muktaa/SeleniumExample•Ready docker image available:◦Docker pull selenium-example

• Customize the sample tests, refer to README: https://github.com/muktaa/SeleniumExample/blob/master/README.md•Headless Selenium tests

@muktaa

Page 18: Using Docker for Testing

Demo• https://github.com/muktaa/SeleniumExample/blob/m

aster/Dockerfile•Docker pull muktaa/selenium-example:headless•Docker run -it -e

TEST_URL=http://54.254.223.84:5555/muktaa/selenium-example:headless

@muktaa

Page 19: Using Docker for Testing

Sample Output

@muktaa

Page 20: Using Docker for Testing

Nightly BuildPUTTING   IT  ALL  TOGETHER  TO  WRITE  NIGHTLY  BUILD  JOB  FOR  OUR  DOCKERIZED INTEGRATION  TESTS

@muktaa

Page 21: Using Docker for Testing

Jenkins Job

@muktaa

Page 22: Using Docker for Testing

Job Configuration

@muktaa

Page 23: Using Docker for Testing

Job Build Step 1#/bin/bash +x

docker-compose --project-name=${JOB_NAME} stop &> /dev/null || true &> /dev/null

docker-compose --project-name=${JOB_NAME} rm --force &> /dev/null || true &> /dev/null

docker stop `docker ps -a -q -f status=exited` &> /dev/null || true &> /dev/null

docker rm -v `docker ps -a -q -f status=exited` &> /dev/null || true &> /dev/null

docker rmi `docker images --filter 'dangling=true' -q --no-trunc` &> /dev/null || true &> /dev/null

docker-compose build

docker-compose --project-name=${JOB_NAME} up &

@muktaa

Page 24: Using Docker for Testing

Job Build Step 2, 3

docker run -itd -v /var/lib/jenkins/workspace/docker-example/test-report:/usr/share/app/target/surefire-reports -e TEST_URL=http://54.254.223.84:5555/ muktaa/selenium-example:headless

@muktaa

Page 25: Using Docker for Testing

Job Build Steps 3, 4

@muktaa

Page 26: Using Docker for Testing

What Next?• Lots More!•Running Selenium tests inside Docker•Using docker swarm to deploy•Using docker machine to manage hosts for testing

@muktaa

Page 27: Using Docker for Testing

References• http://blogs.plos.org/tech/testing-made-awesome-with-docker/• https://www.wouterdanes.net/2014/04/11/continuous-integration-using-

docker-maven-and-jenkins.html• http://making.meetup.com/post/122890386432/steps-towards-automated-

testing-with-docker-and• https://divan.github.io/posts/integration_testing/• https://medium.com/@WoloxEngineering/ruby-on-rails-continuous-

integration-with-jenkins-and-docker-compose-8dfd24c3df57#.7vxoq2gfg• http://anandmanisankar.com/posts/docker-container-nginx-node-redis-

example/• http://www.conductor.com/nightlight/running-selenium-grid-using-docker-

compose/

@muktaa

Page 28: Using Docker for Testing

Thank You!QUESTIONS?

@muktaa