I'm writing a simple program that talks to a router via telnet and issues some simple commands to it. I want to be able to test these commands, that the program responds correctly to the servers output and sends the commands at the right moments. However i can't figure out a good way to do it. Best I've come up with is to create a small telnet server for my unit tests but that seems a bit excessive and i'm hoping there's a simpler way to do it.
Anyone got any ideas?
Best practice in cases like this is to mock the server object. Since you're using python 3, you can simply use unittest.mock
to create a mocked server object for use in testing. Docs here: https://docs.python.org/3/library/unittest.mock.html