Database Reference
In-Depth Information
Unit testing NServiceBus
Visual Studio 2012 has plenty of unit testing features. NServiceBus.Testing offers
testing by sending messages through message handlers and sagas. This includes anything
that a message handler and saga can do, including header manipulation and dependency in-
jection. You can visit http://docs.particular.net/NServiceBus/unit-testing for some basic ex-
amples. For the source code of NServiceBus.Testing , visit https://github.com/Partic-
ular/NServiceBus/tree/develop/src/NServiceBus.Testing .
The very basics of starting unit testing is to create a unit test project in Visual Studio by
adding a new unit test project to an existing solution. See http://msdn.microsoft.com/en-us/
library/hh598957.aspx/ for details.
We will add NServiceBus.Testing from NuGet by visiting http://www.nuget.org/
packages/NServiceBus.Testing/ . We will initialize the tests using Test.Initialize() ,
which is calling NServiceBus.Testing , thus starting the tests with either
Test.Handler<HandleName>() or Test.Saga<SagaName>() .
When a test is built, we can run it or debug it. The test indicators will tell us whether any-
thing failed. We can also put in rules and assertions that if the correct response does not
happen, it will fail the test. This is a great feature of Visual Studio, and there are many
Search WWH ::




Custom Search