我如何预期单元测试中的失败? [英] How do I expect failure in a unit test?

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

问题描述

我们在Clojure中使用 clojure.test

We're writing unit tests for our code in Clojure using clojure.test.

我们的一些测试忽略了API并有意破解代码,以便作为代码中潜在缺陷的文档。

Some of our tests ignore the API and purposely break the code, in order to serve as documentation for latent deficiencies in the code.

但是,我们要区分这些测试的失败和正常测试的失败。

However, we want to distinguish between failures of these tests, and failures of normal tests.

我们没有看到任何建议在 clojure.test 文档中 - 只有(is(thrown?...))

We haven't seen any suggestions in the clojure.test documentation -- only (is (thrown? ...)), which of course doesn't do what we need.

有任何建议吗?基本上,我们正在寻找(是(不是<条件>)),除了测试框架应该记录一个预期的失败 - 类似

Any suggestions? Basically, we're looking for something like (is (not <condition>)), except that the test framework should record an expected failure -- something like this.

推荐答案

我让测试抛出异常,当他们失败了像这样,然后使用 thrown?如果异常按预期到达。有很好的可能存在一个更优雅的方式,但这使得完成的工作。

I have made tests throw an exception when they 'fail' like this, and then used thrown? to test if the exception arrives as expected. There very well may exist a more elegant way, but this gets the job done.

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

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