docker unit test setup

2019-04-29 06:28发布

问题:

I want to setup a unit test environment for my product. I have a web application build on nginx in Lua which use mysql and redis. I think docker will be good for this although i am new to docker. My application runs on centos server (production server).

I am planning to setup different container for mysql,redis and webapp and then write UT application (unit test for Lua using Busted framework) in my mac (My development machine is MAC) or VM to test it. The UT application will talk to docker container nginx and nginx will use container mysql and redis. Is this good ? If yes ,can someone guide me how to do this? maybe some good link? If no , what could be better way. I have already tried using vagrant but that took too much time which shouldn't be in my UT case.

回答1:

For an example how we setup our project template you may have a look at phundament/app and its testing setup.

We are using a dockerized GitLab installation with a customized runner, which is able to execute docker-compose.

Note! The runner itself is running on a separate Docker host.

We are using docker-compose.yml to define the services in a stack with adjustments for development and testing.

The CI configuration is optimized to handle multiple concurrent tests of isolated stacks, this is just done by specifying a custom COMPOSE_PROJECT_NAME.

Some in-depth documentation about our testing process and useful information about docker-compose and dockerized CI.

  • #testing README
  • #testing Docs
  • CI builds
  • Extending services and Compose files
  • Docker-in-Docker for CI?

Finally, Travis CI also supports Docker since a while, but I haven't tested this approach at all.



回答2:

If you are new to Docker based CI, please look at Drone:

  • Official page
  • Github repo
  • Tutorial

There some are drawbacks to this solution (like size of images), but it will get you off the grounds.