Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Manning.The.Art.of.Unit.Testing.with.Examples.in.dot.NET.Jun.2009.pdf
Скачиваний:
18
Добавлен:
21.03.2016
Размер:
9.67 Mб
Скачать

Appendix B

Extra tools and frameworks

This book would not be complete without an overview of some tools and basic techniques you can use while writing code. From database testing to UI testing and web testing, this appendix lists tools you should consider. Some of them are used for integration testing, and some allow unit testing. I’ll also mention some that I think are good for beginners.

The tools and techniques listed below are arranged in the following categories:

Isolation frameworks

Test frameworks

Dependency injection and IoC containers

Database testing

Web testing

UI testing

Thread-related testing

Acceptance testing

TIP An updated version of the following list can be found on the book’s wiki site: ArtOfUnitTesting.com.

Let’s begin.

B.1 Isolation frameworks

Mock or isolation frameworks are the bread and butter of advanced unittesting scenarios. There are many to choose from, and that’s a great thing:

268

Isolation frameworks

269

Moq

Rhino Mocks

Typemock Isolator

NMock

NUnit.Mocks

Here is a short description of each framework.

B.1.1 Moq

Moq is an open source newcomer to the world of mocking and has adopted an API that tries to be both simple to learn and easy to use. The API also follows the arrange-act-assert style (as opposed to the record-and-replay model) and relies heavily on .NET 3.5 features, such as lambdas and extension methods. If you’re planning on working with

.NET 3.5 exclusively, this is a relatively pain-free learning curve, but you need to feel comfortable with using lambdas.

In terms of features, it has fewer than most other mock frameworks, which also means it’s simpler to learn.

You can get Moq at http://code.google.com/p/moq/.

B.1.2 Rhino Mocks

Rhino Mocks is a widely used open source framework for mocks and stubs. It’s also the framework used throughout this book for examples, and it’s discussed more in chapter 5.

Rhino Mocks is loaded with features and has recently moved to using the new arrange-act-assert syntax.

You can get Rhino Mocks at

http://ayende.com/projects/rhino-mocks.aspx.

B.1.3 Typemock Isolator

Typemock Isolator is a powerful commercial isolation framework that tries to remove the terms “mocks” and “stubs” from its vocabulary in favor of a more simple and terse API.

270

APPENDIX B

Extra tools and frameworks

Isolator differs from the other frameworks by allowing you to isolate components from their dependencies regardless of how the system is designed (although it supports all the features the other frameworks have). This makes it ideal for people who are getting into unit testing and want an incremental approach to learning. Because it doesn’t force you to design for testability, you can learn to write tests correctly and then move on to learning better design, without having to mix the two together.

NOTE Full disclosure: While writing this book, I’ve also been working at Typemock.

You can get Typemock Isolator at www.typemock.com.

B.1.4 NMock

NMock is an open source mocking framework that started out as a direct port of jMock. It used to be the de facto mocking framework until Rhino Mocks took its place in the open source world. The main reason it was dethroned is that it did not offer strong typing of method names. (You had to use strings to define expectations on methods.) Lately, it has been getting back into development, and the new 2.0 release marks a nice change in the API. It remains to be seen how well it will do against the current competition.

You can get NMock at www.NMock.org.

B.1.5 NUnit.Mocks

NUnit.Mocks is an ultra-small open source mocking framework that comes built into NUnit as a separate DLL. It initially started life as an aid for testing NUnit internally, and NUnit’s authors still discourage people from using it in their own projects, because it may “disappear” in the future.

NUnit.Mocks is one of the simplest frameworks to learn with, but I don’t recommend using it for anything other than a learning tool.

You can get NUnit.Mocks as part of the installation of NUnit at http://nunit.com.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]