0

我正在寻找想法来引导我为我的应用程序实施组件测试。当然,我使用单元测试通过在单独的项目中使用 TestMethods 来测试我的单一方法,但此时我对更高级别的测试更感兴趣。假设我有一个缓存类,我为每个方法编写了单元测试。它们都包含自己的类实例。当我运行测试时它工作正常,它从该类启动一个对象并对其做一件事。但这并不涵盖该方法被其他方法调用等的现实生活场景。我希望能够测试整个缓存组件。我该怎么做?

4

2 回答 2

2

It sounds like you are talking about integration testing. Unit testing, as you say, does a great job of testing classes and methods in isolation but itegration testing tests that several components work together as expected.

One way to do this is to pick a top (or high) level object, create it with all of its dependencies as "real" objects as well and test that the public methods all produce the expected result.

In most cases you'll probably have to substitute stubs of the lowest level classes, like DB or file access classes and instrument them for the tests, but most objects would be the real thing.

Of course, like most testing efforts, all this is achieved much easier if your classes have been designed with some sort of dependency injection and paying attention to good design patterns like separation of concern.

All of this can be done using the same unit testing tools you've been using.

于 2013-05-30T14:58:45.607 回答
-5

我会下载 NUNIT-Framework

http://www.nunit.org/

它免费且简单

于 2013-05-30T14:49:06.913 回答