Usually our programs depends on third party services. That create some inconveniences for testing, but if we write our unit tests correctly it is not a problem to mock part of code that interacts with third party service. But, what about UI tests? What should we do if we have to test program behaviour that appear only after specific response from third party service?

The first thought is ask owner of this service to create test data for us. I guess it is the most common way. But it is really uncomfortable, because we have to interact with owner of this service. Second thought is just write fake realisation of this service that will return response that we wait. Ok, but UI tests it is the task of testers. Is not it? Testers don't have to know how to write programs. They just have to describe what they want. Not more.





So I have decided to solve this issue and wrote FakeRest. It is a simple Java program that allows you fake third party REST services for testing your application that depends on them. Let me show you one simple example of use FakeRest. There is a configuration of simple REST service that we want to fake.





As you can see we expect "Greetings, my lord" response only for request which has "Admin" value for "user" query param and "superpassword" for "password" query param. All other requests will get "Go away!" response with 403 HTTP status code. Let's check that!

Should we ask some one if we want to get another response, suppose, for another user? No. We just will change our configuration and rerun FakeRest.