Vinay
Vinay

Reputation: 657

Running unit tests inside Docker Container Django

What is the right way of running the unit test cases for django as part of build process ?

We use Jenkins pipeline for building the docker image and container will be started by using a startup script.

Do i need to call the manage.py test before the nginx container was started ? or Do i need to add a post build task in the Jenkins build pipeline to run the tests after the container was started ?

So basically looking for best practice to run tests.. Do we need to run unit tests before the server has started or after the server has started ?

I know that it makes more sense to run unit tests before we start the nginx, but won't it create an increased time with more n more test cases being added in future?

Upvotes: 1

Views: 2123

Answers (1)

nnov
nnov

Reputation: 541

Depends on your test cases. If you are running unit tests only you don't need to. If you are doing something more in your tests like for example calling your apis (functional testing, etc) a good approach (in my opinion) is to create different stages in your jenkinsfile where you first build the docker image, then run the unit tests, then decide what to do depending on the test results. I see this as a good thing because you will be running tests over your app inside the same container (same conditions) it will be running in a production environment. Another good practice would be to add some plugins to Jenkins and have some reports (i.e. coverage).

Upvotes: 2

Related Questions