How to handle the Network failure error message,and how to simulate it?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The way to simulate a network failure (or any sub-system failure) is to replace the real network with a mock object. Then in your mock network object you can set up the method calls to return what ever you require for your testing purposes, be it a successful connection or a failure at any point along the way.
Your code can then be tested against this to ensure that it gracefully fails and reports sensible error messages.
If you look into mocking frameworks you’ll get a lot more information.