odinthenerd
odinthenerd

Reputation: 5552

What is the best way to unit test a COM-Port abstracton library?

I currently unit test our COM-Port library and some basic IO classes which build on it using a null modem cable and a second COM-Port. This works but its quite annoying because the cable needs to be pugged in for the test pass. I tried to use a file rather than the port but this fails because setting the baud rate is not supported by a file. Any tips or ideas? I have not been unit testing for very long so I think I'm missing something.

Upvotes: 0

Views: 69

Answers (1)

Soren
Soren

Reputation: 14688

You should generally avoid external dependencies in unit tests -- they should be self contained, so one option is to mock-out (or stub) the actual IO within the COM-port library if it is appropriately structured to do so, or create a mock for the entire library, so that calling code does not have to depend on the actual hardware.

Upvotes: 1

Related Questions