非关键单元测试失败 [英] Non-critical unittest failures

查看:36
本文介绍了非关键单元测试失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Python 的内置 unittest 模块,我想编写一个一些不重要的测试.

I'm using Python's built-in unittest module and I want to write a few tests that are not critical.

我的意思是,如果我的程序通过了这样的测试,那就太好了!但是,如果它没有通过,也不是真正的问题,程序仍然可以运行.

I mean, if my program passes such tests, that's great! However, if it doesn't pass, it's not really a problem, the program will still work.

例如,我的程序设计为使用自定义类型A".如果它不能与A"一起工作,那么它就坏了.但是,为了方便起见,其中大部分也应该与另一种类型B"一起使用,但这不是强制性的.如果它不能与B"一起工作,那么它并没有被破坏(因为它仍然可以与A"一起工作,这是它的主要目的).未能与B"合作并不重要,我只会错过我本可以拥有的奖励功能".

For example, my program is designed to work with a custom type "A". If it fails to work with "A", then it's broken. However, for convenience, most of it should also work with another type "B", but that's not mandatory. If it fails to work with "B", then it's not broken (because it still works with "A", which is its main purpose). Failing to work with "B" is not critical, I will just miss a "bonus feature" I could have.

另一个(假设的)示例是编写 OCR 时.该算法应该可以识别测试中的大多数图像,但如果其中一些图像失败也没关系.(不,我不是在写 OCR)

Another (hypothetical) example is when writing an OCR. The algorithm should recognize most images from the tests, but it's okay if some of them fails. (and no, I'm not writing an OCR)

有没有办法在单元测试(或其他测试框架)中编写非关键测试?

Is there any way to write non-critical tests in unittest (or other testing framework)?

推荐答案

Python 2.7(和 3.1)添加了对跳过一些测试方法或测试用例的支持,以及将一些测试标记为预期失败.

Python 2.7 (and 3.1) added support for skipping some test methods or test cases, as well as marking some tests as expected failure.

http://docs.python.org/library/unittest.html#skiping-tests-and-expected-failures

标记为预期失败的测试不会被计为 TestResult 的失败.

Tests marked as expected failure won't be counted as failure on a TestResult.

这篇关于非关键单元测试失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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