Presented by Laura Frank, Engineer, Codeship
Testing software is necessary, no matter the size or status of your company. Introducing Docker to your development workflow can help you write and run your testing frameworks more efficiently, so that you can always deliver your best product to your customers and there are no excuses for not writing tests anymore. You’ll walk away from this talk with practical advice for using Docker to run your test frameworks more efficiently, as well as some solid knowledge of software testing principles.
9. Motivators
Update application without breaking things!
Validate functionality of updates
Be able to trust deployment checks (in CI/CD workflow)
Confirm that refactoring didn’t break existing functionality
10. Why do you skip tests?
45%
15%
5%
35% Too slow to run suite 35%
Annoying extra step 15%
Don’t see the point 5%
Slows down deployment 45%
10
11. Frustrators
It takes me an hour to write a single test
My new tests just duplicate existing coverages so there’s no point
(integration overlapping with unit)
It takes my test suite over 20 minutes to run, so I don’t run it locally
Testing distracts me from my normal development workflow
Setting up a testing environment is a huge pain
It takes too long to deploy when I have a huge test suite
12. Frustrators
It takes me an hour to write a single test
My new tests just duplicate existing coverages so there’s no point
(integration overlapping with unit)
It takes my test suite over 20 minutes to run, so I don’t run it locally
Testing distracts me from my normal development workflow
Setting up a testing environment is a huge pain
It takes too long to deploy when I have a huge test suite
13. Using Docker can alleviate
some frustrations
associated with testing.
25. In most cases, we need to
do a bit of setup
before running tests.
26. You can run one-off
commands against a service
with Docker Compose.
27. docker-compose run -e "RAILS_ENV=test"
app rake db:setup
docker-compose run -e "RAILS_ENV=test"
app rspec path/spec.rb
docker-compose up #-d if you wish
Usual Docker Compose development
environment
Run rake task to set up db
Then run tests against Docker services
32. Relying on CI/CD without
adequate test coverage
is not a great idea.
33. Would you rather…
Find out your code is broken by
seeing a failed run of your CI/CD
system?
Find out your code is broken by
seeing 500s on 500s on 500s in
production?
✔
💩
47. A syntax similar to Docker Compose for
service definition…
47
web:
build:
image: my_app
dockerfile_path: Dockerfile
links:
- redis
- postgres
redis:
image: redis
postgres:
image: postgres
48. And use it to also define testing steps…
48
- type: parallel
steps:
- service: demo
command: ruby check.rb
- service: demo
command: rake teaspoon suite=jasmine
- service: demo
command: rake test
49. - type: parallel
steps:
- service: demo
command: ruby check.rb
- service: demo
command: rake teaspoon suite-jasmine
- service: demo
command: rspec spec
Each step is run independently in
a container
49
50. - service: demo
command: ruby check.rb
- service: demo
command: rake teaspoon suite-jasmine
- service: demo
command: rspec spec
And each container may be located in a range
of availability zones
50
51.
52. Docker makes this possible by
providing the means to create
a predictable, reproducible
testing environment.
54. —Edsger Dijkstra
“Testing can be a very effective
way to show the presence of
bugs, but is hopelessly
inadequate for showing their
absence.”
54
55. Resources
Highly recommended talks about development, testing, and lots of
interesting stuff: https://speakerdeck.com/searls
Ruby gem for parallel tests: grosser/parallel_tests
Parallel Docker testing: Jet (from Codeship)
CI/CD with Docker: http://pages.codeship.com/docker
Running commands with Docker Compose:
http://docs.docker.com/compose
The perils of Docker-In-Docker: https://jpetazzo.github.io
This talk: slideshare.net/rheinwein