I created a class that extends from the JSSC library and uses low-level communication methods (sendByte, sendString, etc.). I wanted to test it through JUnit, but I don’t quite know how to do it.
For example, let's look at the following method:
public void openConnection() throws SerialPortException {
serialPort.openPort();
configureConnectionParameters(serialPort);
configureReadListener(serialPort);
}
To make sure that the method works correctly, I need the hardware device to display whether the port is open correctly and there are no exceptions during the configuration process. But playing with external resources during unit testing is usually considered bad practice, so I began to wonder if there are any solutions to such problems (for example, to mock equipment?).
Or do I even need a unit test?
source
share