I have an Android Service that handles communication with a game sync server, sending messages over TCP back and forth.
I would like to be able to unit test the behavior of this service. Namely, when the data is visible on the wire, that the data is read, analyzed and sent, the actual corresponding intention, and when the Service receives the intention, it correctly creates a message that should be sent to the server.
I'm not very good at unit testing, but I'm trying to make part of the testing part of my practice. I'm not sure how to approach something like this. It seems to me that somehow I will need a socket layout and fake input and output streams, but I really do not know how to do this, especially with regard to Android.
Here is the service (greatly reduced for peers):
public class GameSyncService extends Service { Thread mInputThread = new Thread() { private String parseCommands(String message) {
source share