Scrum Gathering Portugal 2016 - Containerizing Tests with Docker

Post on 10-Feb-2017

233 views 0 download

Transcript of Scrum Gathering Portugal 2016 - Containerizing Tests with Docker

Containerizing Tests with Docker 🐳🐙

Stefan Teixeira @stefan_teixeira

stefanfk@gmail.com

• QA Automation Engineer @ Toptal • Blogs: stefanteixeira.com.br (pt-br) /

stefanteixeira.com (en)

Contact:• E-mail: stefanfk@gmail.com • Twitter: twitter.com/stefan_teixeira • LinkedIn: linkedin.com/in/stefanteixeira • GitHub: github.com/stefanteixeira • SlideShare: slideshare.net/stefanteixeira

About me

VMs x Containers

https://www.docker.com/whatisdocker

Why?

Why?

• Reprodutibility

Why?

• Reprodutibility

Why?

• Scalability

Why?

• Scalability

Why?

• Containers are (really) fast

Why?

• Containers are (really) fast

Docker Compose

Docker Compose

• Tool for defining and running multi-container applications

https://docs.docker.com/compose/

Docker Compose

• Tool for defining and running multi-container applications

• Previously known as Fig

https://docs.docker.com/compose/

Docker Compose

• Tool for defining and running multi-container applications

• Previously known as Fig

• YAML ❤

https://docs.docker.com/compose/

Compose File

Containerizing Tests with Docker

Containers != mini-VMs

https://twitter.com/rhein_wein/status/662995114235678720

Motivation

#1

If tests (except unit tests) are hard to run locally, developers will not run them.

¯\_(ツ)_/¯

#2

Sometimes, it’s really hard to configure a test environment.

😫

“Docker delivers a predictable, reproducible testing environment."

🐳❤

(Laura Frank, Codeship)

Examples

App A

App A

DB

App A

DB Mock Service

App A

DB Mock Service

API Tests

App A

DB Mock Service

API Tests

UI Tests

App A

DB Mock Service

API Tests

UI Tests

Security Tests

App A

DB Mock Service

API Tests

UI Tests

Security Tests

Smoke Tests

https://hub.docker.com/u/selenium/

Demo

Demo

• Very simple example, with three containers:

• App (a REST API written in Node.js) • DB (MongoDB database) • API Tests (written with Supertest)

• https://github.com/stefanteixeira/demo-testing-compose

Points of attention

• Logs

Points of attention

• Logs • volumes or data containers

Points of attention

• Logs • volumes or data containers

• Startup time

Points of attention

• Logs • volumes or data containers

• Startup time • wait-for-it, netcat (nc), curl, wait_for module

(Ansible)

Points of attention

• Building images

Points of attention

• Building images • minimal base images: Alpine-linux, Phusion

Points of attention

• Building images • minimal base images: Alpine-linux, Phusion • automate the process

References• “Stop being lazy and test your software”:

• https://www.youtube.com/watch?v=Mx1Il9wIepw • http://www.slideshare.net/rheinwein/stop-being-lazy-and-test-

your-software

• https://hharnisc.github.io/2016/06/19/integration-testing-with-docker-compose.html

• https://docs.docker.com/compose/startup-order/

• https://github.com/vishnubob/wait-for-it

• https://www.ansible.com/blog/six-ways-ansible-makes-docker-compose-better

Stefan Teixeira @stefan_teixeira

stefanfk@gmail.com

Thanks!