Testing NServiceBus

I find it hard to trust my testing is comprehensive when using NServiceBus.Testing. Our business flows are orchestrated from Sagas and handled in pieces by many different MessageHandlers. Without the asynchronous flows I would test the whole flow with a couple of Specflow tests with database and everything. I’m thinking about using Learning Transport or our production Transport (RMQ) for testing, and building new queues before each test and spin up NServicebus. Has anyone experiences with this, good or bad?

Hi Stig,

We do that a lot with our “acceptance tests”. You find them almost everywhere in our repositories. Sometimes we use the transport or the persister directly. Sometimes we replace one component like the transport with something that allows us to simulate specific special scenarios.

@MauroServienti has extracted some of these concepts into GitHub - mauroservienti/NServiceBus.IntegrationTesting: An end-to-end testing toolkit for NServiceBus based messaging systems. that might be beneficial.

One thing that is definitely not trivial is to define the proper infrastructure that makes sure your tests are “immune” to messages from previous runs. It is not always possible or desirable to recreate the whole infrastructure and cleanup because those operations can be expensive and slow down your tests quite a bit.


1 Like