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.

4

1 回答 1

1

对于单元测试,您不应该连接到真实服务器 - 使用测试替身,例如模拟服务器。您还可以编写一些使用真实服务器的集成测试,以确保您正确连接到它等。

于 2014-06-04T14:29:47.647 回答