I participate in a project which, among other things, should control various laboratory instruments (robots, readers, etc.)
Most of these tools are controlled either by using DCOM drivers, a serial port, or by running proprietary programs with various arguments. Some of these programs or drivers include simulation mode, some do not. Obviously, my development computer cannot be connected to all tools, and although I can run virtual machines for tools whose drivers enable simulation mode, some things cannot be tested without a real tool.
Now my own code does not mainly concern actual operations with tools, but also about launching operations, ensuring proper functioning and synchronization between them. It is written in Java, using various libraries to interact with tools and their drivers.
I want to write unit tests for various instrument control modules. However, due to the fact that the tools can fail in many ways (some of them are documented, some of which are not), since the code depends on these partially random outputs, I am a little lost on how to write unit tests for these parts my the code. I reviewed the following solutions:
- only with the actual devices connected, perhaps the most accurate method, but this is not at all practical (insert the plate into the reader, run the unit test, remove the plate, run the unit test, etc.), and not mention the potentially dangerous ones,
- use the layout of the object to simulate the part that actually communicates with the thing; while this one is certainly easier to implement (and run), it will not be able to reproduce the full range of potential failures (as mentioned above, a lot is undocumented, which can sometimes cause unpleasant surprises).
While I'm thinking about going with the latter, am I missing something? Is there a better way to do this?
source share