Django測試:在Travis CI上進行單獨的單元和集成測試

[英]Django testing: separate unit and integration tests on Travis CI


I have a Django project that already has some unit tests using the standard Django testing framework. That works well. Now I want to set up integration tests with Travis CI, but I'm hitting several blockers:

我有一個Django項目,該項目已經使用標准的Django測試框架進行了一些單元測試。這工作得很好。現在我想要和Travis CI建立集成測試,但是我碰到了幾個阻滯劑:

  1. Django docs don't say how to separate self-contained ./manage.py test unit tests from the integration tests, that require external services to be set up. I want to only run unit tests on my dev machine and Travis CI to run both unit and integration tests. How do I separate these?
  2. Django文檔沒有說明如何分離自包含的。來自集成測試的py測試單元測試,需要設置外部服務。我只想在我的dev機器和Travis CI上運行單元測試來運行單元測試和集成測試。我怎么把它們分開?
  3. I have the database on Travis CI filled with some initial data populated during the setup. I want integration tests to run with that, but unit tests to continue using a temporary test-only DB. How do I do that?
  4. 我在Travis CI上的數據庫中填充了在安裝過程中填充的一些初始數據。我希望使用集成測試來運行,但是單元測試將繼續使用臨時測試數據庫。我該怎么做呢?

1 个解决方案

#1


1  

1- You can run any test you want from the manage.py test command. So you can create a file unit_test.py and run only the tests inside this file.

1-你可以運行任何你想從管理。py測試命令。你可以創建一個unit_test文件。並且只在這個文件中運行測試。

manage.py test --help

2- You don't want to do that. Run test against a production/semi-production database is a shame. You need to create fixtures for every tests, and run your tests against a temporary database. If you really want to know the answer, it has already been answered here

2-你不想那樣做。對生產/半生產數據庫運行測試是一種恥辱。您需要為每個測試創建fixture,並對臨時數據庫運行測試。如果你真的想知道答案,這里已經有答案了


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2014/09/04/729b47fb061a7f05e5b408714958c4c8.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com