[TIP] Help: Python Unit testing

Harsh Gupta hagupta at syr.edu
Tue Jul 5 12:58:57 PDT 2016


Hello All,

I have been trying to write a test framework for a pretty simple command server application in python. I have not been able to figure out how to test the socket server.
I would really appreciate if you could help me out in testing this application using unittest.
Please find the commandserver.py file attached. test_commandserver.py is the file i came up with.
Please kindly review it.

The tests cases I came up with are:
1. Start the server
2. Establish connection with client
3. Test the server by sending 3 commands
    - loopback command should  send all payload.
    - print command should print payload
    - close command should close the connection between server and client.

4. Raise error if any other command is send other than listed 3 commands

Other nominal cases
1. Check if both the server and client are closed. It might happen that only one is closed.
2. Go to sleep/Cancel the connection if no command is received after a certain period of time.

Thank You

Harsh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20160705/6a7a14a0/attachment.htm>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test_CommandServer.py
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20160705/6a7a14a0/attachment.asc>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: command_server.py
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20160705/6a7a14a0/attachment.txt>


More information about the testing-in-python mailing list