Question

I am completely new to unit testing/integration testing. I have read that unit tests should use mocks when interacting with external systems, but it seems a lot of manual work.

For external systems I mean:

  • A big database that my class accesses and computes some information
  • An external web service that my class accesses and retrieves a big XML
  • My class implements a serial protocol that connects to an external machine and after a long dialog retrieves lots of data and computes it.

This external system is not always available as it depends on another company. Nevertheless, I want to test my application many times even if not all the external systems are available.

I am thinking of a framework (for Java and/or C++) that does the following:

  • Uses some kind of spy and the real external system and the spy "records" (in a local file) all the interactions with the external system. This needs to be run only once.
  • Automatically a mock is created that "replays" the previous interactions of the real system (accessing the local file). This part can be executed as many times as needed.

If my application (in the "replay" phase) calls the same methods it called the first time (the "record" phase) it should get the same results.

Does such a framework exist? If not, what alternative would you suggest?

I have implemented simulators for many external systems but it doubles my work. For example in the case of serial protocol I have to implement my "client" and also a simulator for the "server". I wonder if there's a way to avoid reinventing the wheel every time.

Was it helpful?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top