Search code examples
javaspringjunitspring-amqpspring-rabbit

JUnit Tests for RabbitMQ


I am building an application using RabbitMQ with Spring: so far so good. To define Unit Tests I am using JUnit targeting an external server. What I wanted to find out is if there is a way to mock the RabbitMQ server to perform tests, and if there is more than a way, which is the best one.

I found some posts around but they were made in 2012 or even before... maybe there's something newer, easier and more effective !

Thanks in advance


Solution

  • I wouldn't try to mock the RabbitMQ server itself; instead, mock your publication methods, channel factories, and so on in order to emulate error conditions (and the happy path, of course). What happens when your FoozleEvent.publish method throws an IOError, for example?