在测试或单元测试的一些基本问题 [英] some basic questions on testing or unit testing

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

问题描述

所以平时我的应用程序是非常小的,我的测试框架只是一个控制台项目。 。我在添加类有静态方法和测试我的code。我觉得这种做法是pretty的直接的和漂亮的(特别是因为你可以看到输出送到)

So usually my apps are very small and my test framework is just a console project. . I add classes in there with static methods and test my code. I find this approach to be pretty straightforward and nice (especially since you can see the output delivered)

我在Visual Studio中一个可爱的小测试项目现在,所以我对你将如何测试的东西似乎没有的单位像的是,有些困惑,例如:

I have a nice little test project in visual studio now, so I was a little confused about how you would test things that don't seem unit like, for example :

Purchase.LoadAllAsync()//finished loading on the loadcomplete event

我会写本什么样的单元测试?特别是因为这将改变基于最新的数据库?

What kind of unit test would I write for this? Especially because this would change based on whats in the database?

我做了一些侦察的SO,发现这个: <一href="http://stackoverflow.com/questions/1257560/when-is-a-test-not-a-unit-test/1257583#1257583">When是测试一个单元测试?

I did some scouting on SO and found this : When is a Test not a Unit-test?

进一步迷惑我,如果测试没有单元测试,你会怎么考呢?

Which confused me further, if a test is not a unit test, how would you test it?

有时候,我通常只写在主窗体小试功能,或炫魅在Silverlight,然后直接删除它。但我想单元测试时,因为测试需要呆在那里,所以你可以重新使用他们的权利?

Sometimes I usually just write a small test function in the main form, or mainpage in silverlight and then just delete it off. But I guess unit testing is used because the tests need to stay there so you can re-use them right?

我很抱歉,如果即时通讯有点太无知了! = P
谢谢

Im sorry if im a little too ignorant! =P
Thanks

更新

也想补充一下:什么是运行得很好,在应用程序本身从外部$ C $名为c失败的测试,但是当。 (这发生在我身上了几次),它发生在你身上的家伙也和/或它的意思是不好的设计?

Also wanted to add: What about tests that run fine in the application itself, but when called from external code it fails. (This has happened to me a couple of times) Does it happen to you guys too and/or does it mean bad design?

推荐答案

如果你的测试依赖于你的控制范围之内的情况下,第一的事情,你应该做的是让他们在你的控制: - )

If your tests depend on circumstances outside your control, the first thing you should do is get them under your control :-)

在换句话说,测试应该使用一个测试数据库,并作为安装的一部分,它应该排空然后填充与已知的,predictable数据数据库。或者,你可以把存根程序和完全避免数据库访问。

In other words, your test should use a testing database and, as part of the setup, it should empty then populate that database with known, predictable data. Alternatively, you can put in stub routines and avoid database access altogether.

一个非确定性测试是大约为大豆奶牛一样有用。它可能的似乎的工作,但不知怎么的结果并不如你预期的那样令人满意。

A non-deterministic test is about as useful as a soy-milk cow. It may seem to be working but somehow the results aren't as satisfying as you expected.

这篇关于在测试或单元测试的一些基本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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