Django 使用 Hudson做CI服务器实践记

我的环境:
开发环境: Windows XP
运行环境:Ubuntu 11.10
Python:2.7
Django:1.3.1

国内没有找到比较好的翻译和实践性的博文,于是去了Google,按照一篇文章的做法一步步实现,实践到“Displaying unit test results”的时候因为原文使用了自己的bash,而我需要使用Django自带的unit test的框架,于是修改这一段

原文:

Displaying unit test results

What this isn’t doing it making some pretty graphs and charts. Let’s see about getting some of that enabled.

Pygments uses Nose tests for it’s unit tests. That’s pretty nice, because Nose includes a mechanism to output the format of the tests into Java-based JUnit format, and Hudson in turn knows how to make pretty pictures from that format. Since we installed the nose library earlier, we can take advantage of it. Probably the “right” way to do this would be to change the Makefile to invoke the tests that output XML for the unit tests. For right now, we’ll just shim it into place with new build steps.

Change the content of the Execute shell build step and replace it with
python tests/run.py --with-xunit save the configuration and invoke “Build Now” now look in the workspace in you should find a new file called “nosetests.xml” in the tests subdirectory.

Let’s get that graphed…

Go to the job configuration and enable “Publish JUnit test result report”. It will have a text field so that you can tell it where to find the results. It uses an Ant format for finding filenames in an existing directory structure. In this case use **/tests/nosetests.xml Save the config invoke Build Now

现在我的做法:

使用unittest-xml-reporting,官网:https://github.com/danielfm/unittest-xml-reporting#readme

具体做法:

1)shell输入安装unittest-xml-reporting:

pip install unittest-xml-reporting  

2)在Django项目的Settings.py输入:

TEST_RUNNER = 'xmlrunner.extra.djangotestrunner.XMLTestRunner'   TEST_OUTPUT_VERBOSE = True   TEST_OUTPUT_DESCRIPTIONS = True   TEST_OUTPUT_DIR = 'unitTestResults'  

3)回到shell,执行:

python manage.py test  

4)执行完后会发现多出一个名为"unitTestResults”的文件夹,点进去看一下,发现里头有很多xml的文件生成

5)进入hudson的项目管理“configure”

IP Addr:8080/job/Your Project/configure

6)钩上“Publish Junit test result report”

7)地址填上“*/unitTestResults/*.xml”

8)保存

9)做个新Build,点 Build Now

10)Build完后会发现多出一个“Latest Test Results”的链接。点进去可以查看详细信息

11)同时会发现右边多出一个名为“Test Result Trend”的图

后面的就和原文一样了

Now you’ll see a new element in the web user interface called “Latest Test Result” which you can dig into. If you invoke “Build Now” again, it will start graphing the results of the tests and making that trend available in the project view. Right now this graph is going to be really darned boring, because there aren’t any changes between builds. Once more code starts rolling in, you’ll see changes with the number of tests being invoked. You can also click on that link and see the tests that were invoked. For python folks, remember that we’re shimming Python unit tests into a JUnit conceptual framework, so there are going to be some “leaky abstractions here”. In particular, test names, classes, and such may not alway match up with expectations. I have more details on how to enable XML output for a Django based test runner that I’ll post in another write up… uh, later.

Django 使用 Hudson做CI服务器实践记

按照原文的做法,我也顺利的生成了Code Coverage和Pylint

这里要感谢原作者Joe Heck

附上原文的链接:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/db90cc66772138e4b5c179959dcd5b8a.html