0

We currently have a test that brings the test to and address page.

The test types in 123 and selects the first suggestion by Google's Address Autocomplete API.

What we are running into is that we are hitting our quota, and the test are failing.

Is there a way to either mock the response, we know go to mock responses just not this one, or unit test to make sure that it works?

Thanks John

1 Answer 1

1

Mocking tools and techniques would highly depend on your development stack.

Generally speaking, you would need to inject the service as a dependency - so, in the production code, you would inject the real Google Service and on test code you would inject a mock.

class GoogleAbstractService
class GoogleService extends GoogleAbstractService // Real service
class GoogleMockService extends GoogleAbstractService // Mocked service
class AnyClientOfTheService
      constructor(GoogleAbstractService googleService ){
         this.googleService = googleService ;
      }
new AnyClientOfTheService(new GoogleService()); //production code
new AnyClientOfTheService(new GoogleMockService()); //test code

GoogleService would call the real service, whereas GoogleMockService would promptly return some value (of the same type), but never reaching the network.

1
  • @jp-hamlett If you have found this answer acceptable, could you mark it as accepted? Thanks! Commented May 11, 2018 at 15:25

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.