Python 单元测试哲学和排序

标签 python unit-testing

虽然单元测试的理念是测试可以按任何顺序运行并且它应该通过,但是如果您正在实现一个没有其他与服务器通信的方式的 API 怎么办...并且您需要测试某个特定的非常基本的功能(例如删除),然后才能执行更复杂的任务?那么订购测试是否合理?

如果是这样,我该如何使用 python 的 unittest 模块来实现?

最佳答案

您似乎已经意识到您的单元测试应该是独立的。我可以看到您想以某种固定顺序运行测试的唯一其他原因是,如果早期测试失败,您希望停止运行该套件。为此,您可以使用 command-line option

-f, --failfast

Stop the test run on the first error or failure.

顺便说一下,测试是按字母顺序运行的:

the order in which the various test cases will be run is determined by sorting the test function names with respect to the built-in ordering for strings.

( docs )

关于Python 单元测试哲学和排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9637534/

相关文章:

unit-testing - 你如何测试视觉组件?

.net - MSTest V2 在哪里

python - 如何修复此错误,类别没有属性 'get_impath' 是什么意思?

python - mysql 中的正则表达式解析存储

javascript - 使用 jqlite 单击 href 进行 jasmine 单元测试

unit-testing - soapUI 与 rest-assured 的 REST API 测试

php - 如何正确地重新生成 session ID?

python - Django ModelForm 不保存数据

python - matplotlib:如果我设置无花果高度,x 传说被切断

python - cv2.imwrite 不保存图像