Django vs Python2.7单元测试TestCase? [英] Django vs Python2.7 unittest TestCase?

查看:124
本文介绍了Django vs Python2.7单元测试TestCase?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Django应用程序,我正在努力决定如何为我的代码设置单元测试。看看Django文档,我看到单元测试有两个选项,Python2.7的内置测试和Django的自定义TestCase类。当试图查看哪一个使用,Django似乎只列出了Python的好处(https://docs.djangoproject.com/en/dev/topics/testing/?from=olddocs#which-should-i-use)。

I'm building a Django app, and I'm trying to decide how to set up unit-tests for my code. Looking at Django documentation, I see that there are two options for unit-tests, Python2.7's built-in tests and Django's custom TestCase class. When trying to see which one to use, Django seemed to only list benefits for Python (https://docs.djangoproject.com/en/dev/topics/testing/?from=olddocs#which-should-i-use).

哪个单元测试框架比较好?

Which unit-test framework is preferable?

推荐答案

:使用Django TestCase 。它完成了所有的python unittest.TestCase 可以做的更多。

Short answer: use Django TestCase. It does everything that the python unittest.TestCase can do and more.

python和Django TestCase 类都用于单元测试。我应该使用哪一个 部分,您链接到的是将单元测试文档测试进行比较。

The python and Django TestCase classes are both for unit tests. The Which should I use section that you link to is comparing unit tests with doc tests.

Django TestCase 只是python unittest.TestCase 的扩展。如果您使用的是较早版本的Python,那么Django TestCase 允许您使用一些整洁的功能,如 assertRaisesExp 仅适用于 unittest.TestCase for python 2.7。

The Django TestCase is just an extension of the python unittest.TestCase. If you are using an earlier version of Python, then the Django TestCase allows you to use some neat features like assertRaisesExp which are only available in unittest.TestCase for python 2.7.

由于您使用的是Python 2.7,需要使用Python 2.7功能的Django TestCase ,但还有很多额外的功能,例如 fixture loading ,这意味着你应该使用Django TestCase

Since you are using Python 2.7, you don't need to use the Django TestCase for the Python 2.7 functionality, but there are still lots of extra features, for example fixture loading, which mean you should use the Django TestCase.

这篇关于Django vs Python2.7单元测试TestCase?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆