0

I'm implementing unit tests (with Catch) in C++ program that performs "API" functions. It consists of a big class with public methods which user could use to interact with an external device. Moreover, there are special private "system" methods providing other functionality. This device sends the responces, its own stats and so on. How should I divide whole class to unit tests correctly? There are many information about simple programs like calcs but nothing special about more narrow cases. Should I add whole class to the test and use only one method for the each one test or should I copy only method from this class and give predefined input parameters?

Stanislav
  • 73
  • 8
  • 1
    You should not copy or divide anything. Unit tests are separate code pieces that may utilize some functionality of your class. Anyway, in its current form question is too broad. – user7860670 Oct 13 '17 at 14:20
  • You simulate the external devices with an oversimplified object that gives a predictable canned response. Look up dependency injection. – Kenny Ostrom Oct 13 '17 at 14:29
  • @VTT Yes, I have catched this idea but my question about adding this test in my framework. E.g, I have got class which method sends a message to the device, get the ack and reporting the result to the terminal and to the log. So I know input data and data which should this method gets. In this case I should use some methods except this one (connecting, messaging and etc) to get the response from the device. – Stanislav Oct 13 '17 at 14:33
  • @KennyOstrom Thank you for the answer! This is something what I thought about. But should I implement "service" functions like reading from the serial port for testing "api" level? Or I just could directly give the response from this simulated device? – Stanislav Oct 13 '17 at 14:42

0 Answers0