如何知道您的单元测试治具是否“合适大小"? [英] How to know if your Unit Test Fixture is “right-sized”?

查看:83
本文介绍了如何知道您的单元测试治具是否“合适大小"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何知道测试治具"的尺寸是否合适. 测试装置"是指其中包含一堆测试的类.

How do you know if you "Test Fixture" is right-sized. And by "Test Fixture" I mean a class with a bunch of tests in it.

我经常在测试装置上注意到的一件事是,它们变得有些冗长.看到它们可能也不够冗长,您如何看待单元测试的大小正确?

One thing that I've always noticed with my test fixtures is that they get to be kind of verbose; seeing as they could also be not verbose enough, how do you get a sense of when your unit tests are the right size?

我的假设是(至少在Web开发的情况下)每页应该有一个测试夹具类.

My assumption is that (at least in the context of web development) you should have one test fixture class per page.

我知道这是一个很好的报价,它是:

I know of a good quote for this and it's:

达到完美,不是没有剩余可添加,而是没有剩余可删除." -Antoine de Saint-Exupery.

"Perfection is achieved, not when there is nothing left to add, but when there is nothing left to remove." - Antoine de Saint-Exupery.

推荐答案

我想这更多是针对您的问题:

This is more to your question I think:

我使用的指标是测试直到您感到舒服为止"(不确定来源).我测试直到我对自己的代码正确感到满意为止.如果您有疑问,则可能没有足够的测试.如果您觉得自己在浪费时间,就应该停下来.

The metric that I use is "Test until you are comfortable" (not sure of the source). I test until I am comfortable that my code is right. If you have doubts, you probably don't have enough tests. If you feel like you are wasting your time, you should probably stop.

重新阅读,我认为以下内容无法回答您的问题:

Re-reading, I think the following does not answer your question:

按照测试治具的定义作为设置函数,对象和模拟对象,使被测系统"功能必需:在编写测试时,通常会有代码被复制,我通常会对该代码进行重构并将其隐藏在区域(C#)中.我尝试将测试保持在5到10行范围内,因此,如果有超出此范围的代码或使测试的含义模糊不清,则将其放在Fixture区域中.我通常不会过多担心灯具的尺寸.我更担心要确保我有足够的测试并且我的功能已经过测试.

Going by this definition of Test Fixture as the setup functions, objects and mock objects that are required to make the System Under Test function: When I write tests, there is usually code that get replicated, I typically refactor that code and hide it in a region (C#). I try to keep my tests in the 5-10 line range, so if there is code that exceeds this or obfuscates the meaning of the test, I put in the fixture region. I typically don't worry about too much about fixture size. I worry more about making sure I have enough tests and that my functionality is tested.

这篇关于如何知道您的单元测试治具是否“合适大小"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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