PDA

View Full Version : Mock RabbitMQ for testing



kayser
Jun 13th, 2012, 02:12 AM
Hi

is there already a way to mock a rabbitMQ environment to test code that uses rabbitTemplate and/or a MessageListener implementation? We use rabbitmq with great efficiency but for better code quality we want to add tests without the need of a rabbitMQ running in background.

Cheers

Kay

Gary Russell
Jun 13th, 2012, 10:05 AM
There are quite a few test cases in spring-rabbit that use Mockito to mock the connection factory, connections etc. For example, see CachingConnectionFactoryTests.java

There are others (integration tests) that use the real rabbitMQ, but use a JUnit @Rule to detect if the broker is running, so they don't fail if it's not.