Skip to content

Provide easy way to override BASE_URL to allow functional application testing #37

@jiffle

Description

@jiffle

It is a standard practice of modern software development to perform functional testing of any application by running it against mock servers which emulate the backend services with which the application interacts. This allows negative path (error) responses from the backend service to be introduced and test that the application handles them correctly

In order to do this the Base URL used to interact with the Plivo API needs to be overridden. Since the Retrofit instance is private and there is no way replacing it, modifying the protected BASE_URL is the only way to achieve this with the helper library.

Unfortunately protected access means that the application code to override the base URL ends up looking like this:

// horrible hack using fake subclass to get around the lack of a formal method to override the base URL for testing
final String baseUrlOverride = System.getProperty("PLIVO_BASE_URL");
if( !Strings.isNullOrEmpty( baseUrlOverride)) {
   LOGGER.info( "Overriding Plivo BASE_URL with '{}'", baseUrlOverride);
   PlivoClient dummy = new PlivoClient( authId, authToken) {
      {
         PlivoClient.BASE_URL = baseUrlOverride;
      }
   };
}
plivoClient = Plivo.init( authId, authToken);

And worse, this is not test code, this is hack code inside the application itself.

Please extend PlivoClient to allow a cleaner way to override the BASE_URL for test environments.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions