2

What is the main points of testing xmpp client?

I'm writing a chat, sort of XMPP client using JsJac library. Now I need to test behavior of my client after different server signals. For instance - that when server send's some error to my client - it would trigger ondisconnect callback. I also should test (in separate test) that when this callback triggered - certain conditions are met.

The question is should I do connection to real server in any test or I can somehow write some mock for it?

I can emulate server messages in such a way (CoffeeScript code):

error = JSJaCError '503', 'cancel', 'service-unavailable'
xmpp._handleEvent 'onerror', error

but the problem is that xmpp object should be in connected state to do this.

SET001
  • 11,480
  • 6
  • 52
  • 76
  • Check out [Beautiful XMPP Testing](https://el-tramo.be/documents/beautiful-xmpp-testing/BeautifulXMPPTesting.pdf) (PDF) by Remko Tronçon – CrazyPyro Jan 19 '20 at 02:07

1 Answers1

1

For unit tests you should not connect to a real server - use a test double, e.g. a mock server. You may also write some integration tests that use the real server to ensure you are connecting to it correctly, etc.

Mike Stockdale
  • 5,256
  • 3
  • 29
  • 33