Python - doctest vs. unittest [英] Python - doctest vs. unittest

查看:471
本文介绍了Python - doctest vs. unittest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开始在Python中进行单元测试,我想知道是否有人可以解释doctest和unittest的优点和缺点。

I'm trying to get started with unit testing in Python and I was wondering if someone could explain the advantages and disadvantages of doctest and unittest.

您将使用哪些条件?

推荐答案

有价值。我同时使用doctest和鼻子取代单元测试。我使用doctest的情况下,测试提供了一个用法作为文档实际有用的例子。一般来说,我不使这些测试全面,仅针对信息。我有效地使用doctest反向:不基于我的doctest测试我的代码是正确的,但基于代码检查我的文档是正确的。

Both are valuable. I use both doctest and nose taking the place of unittest. I use doctest for cases where the test is giving an example of usage that is actually useful as documentation. Generally I don't make these tests comprehensive, aiming solely for informative. I'm effectively using doctest in reverse: not to test my code is correct based on my doctest, but to check that my documentation is correct based on the code.

原因是我发现全面的doctests会使你的文档太多,所以你会遇到不能使用的docstrings或者不完整的测试。

The reason is that I find comprehensive doctests will clutter your documentation far too much, so you will either end up with either unusable docstrings, or incomplete testing.

实际测试代码,目标是彻底测试每一个案例,而不是说明什么是通过示例,这是一个不同的目标,我认为是更好地被其他框架满足。

For actually testing the code, the goal is to thoroughly test every case, rather than illustrate what is does by example, which is a different goal which I think is better met by other frameworks.

这篇关于Python - doctest vs. unittest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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