Closed rzbrk closed 2 years ago
From the main repo folder all tests can be invoked by:
python -m unittest discover ./tests
The purpose of this issue was to provide the fundamentals of unit testing. This is achieved and the issue can be closed. Completing the set of unit tests will be tracked in dedicated issues.
Unit testing is quite a challenge because most of the class methods rely on serial communication with the module. Unit tests should be independent from the module hardware connected via serial port.
Basically, one can "mock" or simulate the module. To ease this, the serial device that is used by the class PyVoiceRecognitionV3 now will have to be instanciated "outside" of PyVoiceRecognitionV3. When an instance of PyVoiceRecognitionV3 is created such a serial device has to be provided to the class.
However, existing tools to mock a serial device like unittest.mock or mock_serial did not work as expected. The reason for this is the rather compliccted way of communication with the voice recognition module in the class method _rcv_rsp(). But this "complicated" communication scheme is very reliable.
Therefore, for testing purposes I dicided to write a custom mock for a serial device "MySerMock". It provides the few methods of PySerial that is used by the class PyVoiceRecognitionV3 like read(), write(), reset_input_buffer() or inWaiting().