没有断言的单元测试

编程入门 行业动态 更新时间:2024-10-27 02:24:26
本文介绍了没有断言的单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有时候,我遇到一个没有断言任何内容的单元测试.我今天早上遇到的一个特定示例是测试是否在满足条件时写入了日志文件.假设是如果没有错误抛出,则测试通过.

Occasionally I come accross a unit test that doesn't Assert anything. The particular example I came across this morning was testing that a log file got written to when a condition was met. The assumption was that if no error was thrown the test passed.

我个人对此没有问题,但是编写没有任何断言的单元测试似乎有点代码味".

I personally don't have a problem with this, however it seems to be a bit of a "code smell" to write a unit test that doesn't have any assertions associated with it.

只是想知道人们对此有何看法?

Just wondering what people's views on this are?

推荐答案

这将是官方的方法:

// Act Exception ex = Record.Exception(() => someCode()); // Assert Assert.Null(ex);

更多推荐

没有断言的单元测试

本文发布于:2023-11-03 19:57:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555947.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:断言   单元测试

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!