I am doing GUI tests for my network application and I'm wondering if I should stub out mock responses, or if it's OK to keep using the network for the GUI tests.

It seems to me the main benefits of stubbing the responses are:

  1. Speed
  2. Robustness - no false errors because of network problems

And the cons are:

  1. Server interaction (real world) - doesn't test this
  2. Time to implement and maintain mock up (for a large application)

Are the pros worth the cons? Are GUI tests about testing the actual application and if it runs for a real user connected to the server, or are they more similar to regular unit tests, but for the GUI - are they just trying to test the GUI and don't care about server interaction.


This question specifically relates to GUI tests, not regular unit tests, and is questioning the value of stubbing mock responses in the GUI tests vs. using the server normally.


1 Answer 1


Unit tests are for testing your code, not real-world scenarios. Specifically, unit tests should validate that your code produces correct outputs for given inputs. Nothing more.

Server latency and responsiveness are certainly worth testing, but not with unit tests. Those would be covered by system tests.

The risk of relying on networking for unit tests is they may fail due to problems outside the scope of the unit of code being tested. If you have a CI server with automated unit testing (you should), your build might fail if e.g. MIS takes the remote server down for maintenance. That is a false negative: the failure indicates a problem in your code, when the problem is an unresponsive server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.