2

I have a node service which uses AMQP to perform a remote procedure call, so it publishes a messages to a given amqp exchange and expects a response on a given amqp queue with the results of that call.

I am looking for a good unit test strategy which mocks the amqp connection can send a message based on a given input. I have looked into amqp-mock module but this seems to require a connection to a real amqp server and this was something I wanted to avoid.

Has anyone implemented anything similar or have a good strategy for this?

4

2 回答 2

1

您可以使用“a”模块轻松模拟 require :

// Example faking require('./foo') in unit test:
var fakeFoo = {};
var expectRequire = require('a').expectRequire;
expectRequire('./foo').return(fakeFoo);

// in sut:
var foo = require('./foo'); // returns fakeFoo
于 2013-06-23T08:26:48.273 回答
0

你可以试试node-amqp-mock

于 2014-04-14T07:03:38.453 回答