Reputation: 47
Some context : I currently working on a home automation project which involves arduino controllers I need to connect to via TCP/IP. The arduino works as a server.
My Question : How can I mock this arduino connection for testing purpose? Couldn't find any good resource to learn from. Sorry if my question is duplicate, but I did not find any answer on SO that fits my need.
Any help will be appreciated !
Upvotes: 3
Views: 5823
Reputation: 169
Take a look at WireSham: a TCP mocking service that enables to load a previously recorded TCP dump (ie using Wireshark) and creates a virtual server simulating traffic.
Upvotes: 3
Reputation: 105
I'm not sure, how exactly your system design is or what you want to mock, but I see three ways how you could test:
Connect with netcat to the server. Netcat allows you to test text-protocols by sending your request to the server and manually checking the response.
Open a connection with a client-socket in your favorite language. You should find plenty information on how to do that on SO.
Use scapy to build a TCP handshake, if you want to test specific parts of TCP. Basics for TCP can be found in rfc793.
If I did not answer your question, please provide more details on what you want to do, how your overall system architecture is and what programming language you want to use.
Upvotes: 0
Reputation: 6096
I'd suggest you don't try and mock at such a low level.
Create a meaningful interface that encapsulates the operations you might want to perform against the arduino server. Your code should depend on that and this interface may be mocked for your unit tests.
You will need a concrete class that implements the interface and interacts with the server. Don't try and unit test it - write an integration test for it that hits a real server.
Upvotes: 0