有没有单元测试的完整性的一个很好的措施 [英] Is there a good measure of completeness of Unit tests

查看:143
本文介绍了有没有单元测试的完整性的一个很好的措施的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类,我需要进行单元测试

I have a class that I need to Unit Test.

有关背景我开发的C#和使用NUnit,但我的问题是更多的理论:

For background I'm developing in c# and using NUnit, but my question is more theoretical:

我不知道,如果我写了足够的测试方法,如果我检查了所有的场景。
是否有已知的工作方法/最佳做法/为的规则集合?

I don't know if I've written enough test methods and if I checked all the scenarios. Is there a known working method/best practices/collection of rules for that?

类似


  • 在你的类检查每一个方法......喇嘛喇嘛

  • 检查所有的插入到数据库...喇嘛喇嘛

(这是可能的规则,一个愚蠢的例子,但如果我没有愚蠢的东西在我的脑海,我不会问这个问题)

(this is a silly example of possible rules but if I had something not silly on my mind I wouldn't ask this question)

推荐答案

有单元测试的几个可用的指标。看看到两个代码覆盖率和正交试验。

There are several available metrics for unit testing. Have a look into both code coverage and orthogonal testing.

不过,我会说,这不是解决问题的最佳途径。尽管100%的代码覆盖率是一个令人钦佩的目标,它可以成为排序度量的这掩盖了测试,实际的质量。

However, I would say that this is not the best way of addressing the problem. While 100% code coverage is an admirable goal it can become the sort of metric which obscures that actual quality of the tests.

我个人认为,你会得到从调查更好的结果测试驱动开发 - 采用这种方法你知道你有很好的覆盖(无论是在代码行方面和在你的类的功能而言),因为你一直在写测试你写的类方法之前行使你的类本身

Personally I think you would get better results from investigating test driven development - using this approach you know you have good coverage (both in terms of lines of code and in terms of functionality of your class) because you have been writing the tests to exercise your class before you wrote the class methods themselves.

这篇关于有没有单元测试的完整性的一个很好的措施的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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