简体   繁体   中英

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?

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 (ie coverage).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM