Question

I am currently developing a Java Desktop Client. My application is based on socket and there are a lot of methods based on network operation. Do I need to test this kind of methods? how can I test it? Currently I set up an socket server only for testing. But in this way I have to always run the socket server before testing.

Another question is that do I need to test methods related to GUI operation and how? Can JUnit simulate the GUI operation? These methods are usually void method. Is there any way to test a void method?

Was it helpful?

Solution

This should have been 2 different questions. I'll address the first part only:

If you care whether your program actually works, then yes, you absolutely should test it, in one way or another. If you can't find a better way to do it, then manual testing could be used. Yes, you will need to run a server while you test. But not testing really just means that your users are "testing" it for you. When they find bugs, it will be harder to fix them than if you found them yourself while running in your development environment.

Tools like JUnit are useful, but you don't have to use them to automate your tests, if they don't do what you want. You can just as easily write your own test script, which starts up an instance of the server, and then drives the client code through a series of operations. If one of your checks fails, just throw an exception and crash the test script.

Since you mentioned JUnit, I'm guessing that you are working in Java. If you decide to write a test script like I just described, remember you can use any JVM-compatible language to do so.

If you find the network-related integration tests are too slow to run them all the time, then you don't have to do so. Just keep that test script around, and run it any time you change something which might affect the network-related functionality. Or at least run it before you release a new version of the program to your users.

In my experience, comm and networking are rich sources of hard-to-find bugs. There are so many corner cases. What happens if a client suddenly drops the connection part-way through a request? What if there are too many clients? What if a message is corrupted somehow in transit? Depending on how stringent your requirements for reliability are, you may need to do a lot of stress testing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top