3
votes

I am new to IBM Websphere MQ.

In our projet, I have implemented code to read messages from IBM MQ.

I have installed IBM WebSphere client and I am using references of IBM.XMS and IBM.XMS.Client.WMQ to create the connection and read the message from the queue.

XMSFactoryFactory xff = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
IConnectionFactory cf = xff.CreateConnectionFactory();

I have set the necessary properties like HostName, Channel, Port, QueueManager.

I have created the MessageListener:

MessageListener messageListener = new MessageListener(Method to process the message);

I have assigned listener to consumer:

consumer.MessageListener = messageListener;

I am able to connect to queue manager, read the message and display that message in WPF window.

Now for above code I have to write the UnitTest.

As per my knowledge, in unittest we won't be creating connection and reading from queue so how can I mock above code so that I can pass dummy message and check that.

1
Abstract the dependencies behind an interface to make them mockable. that way your can swap them out for mocks when testing.Nkosi
Show a definition of the listener and an example of how the listener is consumed. From that the required/expected functionality can be ascertained and an abstraction can be created.Nkosi

1 Answers

0
votes

The XMS API you are calling will actually communicate with a queue manager. So without a queue manager the API's will fail and so will the unit test.