NodeJS + RabbitMQ (amqplib): How to write good Unit Test against them.

4,557 views
Skip to first unread message

agcarl...@gmail.com

unread,
Sep 5, 2018, 10:39:31 AM9/5/18
to rabbitmq-users

Greetings,


Currently, I am working on RabbitMQ on NodeJS. I was trying to figure out the best way to write unit tests against amqplib.

The tutorials and examples are great; however, I can't find in their websites any examples about unit tests:

I tried to use the package amqp-mock but its not compatible (for example, in the examples one can use close(), and the amqp-mock uses done()).

Currently, I use Sinon and Chai


Would anyone mind to provide some examples or point me to where I could read some examples?

Michael Klishin

unread,
Sep 5, 2018, 11:17:08 AM9/5/18
to rabbitm...@googlegroups.com
Take a look at integration tests in any of the clients. Bunny and Pika are probably most approachable.

I personally think mocked-only tests is a terrible idea. I've seen applications where you could delete entire modules/packages/classes
and tests passed because of mocks.

Bunny test suite uses docker-compose or 2 local services (RabbitMQ with a setup script + Toxiproxy) and a few basic asynchronous and concurrent programming techniques,
the most common and also trickiest of which is "wait for a certain event to happen, then assert on something".

It takes some effort to automate such integration suite setup but it is also infinitely closer to how things will actually work in production. And with Toxiproxy and similar
tools you can test failure scenarios that are realistically impossible to test with mocks.

Mocks are great for the first couple of days. Then, to paraphrase Rich Hickey, they begin mocking you for using them.

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
MK

Staff Software Engineer, Pivotal/RabbitMQ
Reply all
Reply to author
Forward
0 new messages