JUnit tests for RabbitMQ

I am building an application using RabbitMQ with Spring: so far so good. To define unit tests, I use JUnit to target an external server. I would like to know if there is a way to trick the RabbitMQ server into conducting tests, and if there is more than a way which is the best.

I found several posts, but they were made in 2012 or even earlier ... maybe something new, easier and more efficient!

Thanks in advance

+4
source share
3 answers

RabbitMQ; , .., (, , ). , FoozleEvent.publish IOError, ?

+6

; . RabbitTemplate, .

, , , JUnit @Rule , -.

+3

RabbitMQ Java, : rabbitmq-mock.

, . amqp-client ConnectionFactory RabbitMQ - ( ) .

pom.xml:

<dependency>
    <groupId>com.github.fridujo</groupId>
    <artifactId>rabbitmq-mock</artifactId>
    <version>1.0.9</version>
    <scope>test</scope>
</dependency>

, ConnectionFactory, Spring Spring-Boot :

@Configuration
@Import(AppConfiguration.class)
class TestConfiguration {
    @Bean
    ConnectionFactory connectionFactory() {
        return new CachingConnectionFactory(new MockConnectionFactory());
    }
}

, !

0

All Articles