1

I'm developing a socket server game using java. I want to test if server works properly (how it handles received messages, process and response in right way...) without using game client(heavy and not completed). Messages from client maybe raw binary and encrypted.

Is there a framework, or testing tool for this case?

tiboo
  • 8,213
  • 6
  • 33
  • 43
  • `telnet localhost 12345` where 12345 is you port number – Ingo Nov 12 '13 at 09:07
  • 2
    _"how it handles received messages, process and response in right way without using game client"_ - this sounds like the entire logic for sending messages to the server is in the game client. This is not good and not testable. Extract the networking part in a unit testable library. You can now test client access to your server without running the client, test message parsing without sending messages and perform load tests without running the client. The client itself uses this library also. See @Lens answer. – CodeCaster Nov 13 '13 at 09:41

2 Answers2

2

There are several steps that I take when testing client server systems and mostly I tend to use "normal" unit testing frameworks for this kind of thing, though it only works if you've already designed your code to be unit testable. I also often write a specific stress test client for the server; this can create many thousands of concurrent connections and perform operations on the server and check that it gets the expected results.

For initial server testing you want to have a set of unit tests in place for the key server components; message parsing, etc, and you want to have isolated these components from the code that actually deals with the network (so that you can test it all in a unit test). Push data into the server's message parser and make sure that it parses correctly, and calls the right things, etc.

You can then use your normal unit testing framework to create an instance of your server object (with suitable mocks) which listens on the network and then create a simple client which you instantiate within the unit test and which tests aspects of the server. Often you'll find that there are only a small number of things you actually MUST test like this. Normally connection establishment and termination issues which you want to test with the network as well as independently of it (after all, you can call the connection establishment and disconnection code on your server class from a normal unit test anyway).

Finally you need a custom client which understands your protocol and can put pressure on the server with 1000s of clients - this is the best way to drive out performance and threading issues.

I tend to work on all of these things from the very start; see this blog post for more details.

Len Holgate
  • 21,282
  • 4
  • 45
  • 92
1

If you want to do it by hand, I would suggest telnet or, if you're using Linux, you can use netcat command nc.

If you want something that can be automated, e.g. a unit test, and you're familiar with Python, I would recommend using Twisted: Twisted Examples

Hope this helps

jcm
  • 2,568
  • 14
  • 18
  • You're welcome. Yes, I used it long some time ago and twisted is a really interesting framework. – jcm Nov 14 '13 at 11:12