Question

How do you test a hybrid application when your requirement is to sign off and ship the very same package? You have a single hardcoded URL your AJAX calls are going to go to, but actually this endpoint needs to be different in test and production environments.

  • Override the hosts file is not an options because it would require to root all test devices.
  • Serve and host custom DNS server or HTTP proxy is an overkill.
  • Have an application option is against the requirements, the end users can not be exposed to such a setting.
  • Have a cookie to optionally override the URL would work but how to I add a cookie manually to a hybrid app running on a tablet?
  • Have a local storage setting to optionally override the URL would work but how to change local storage manually?

Is there a way to have but hide an application configuration option, setting from the end user?

Testing is performed on iOS tablet running a native app package.

Was it helpful?

Solution

If you really really want to ship the exact same code all the time, you could easily use local storage. In your app:

if(!localStorage.getItem('env')) localStorage.setItem('env', 'production');
switch(localStorage.getItem('env') {
    case 'testing': endpoint = 'http://testserver'; break;
    case 'production': endpoint = 'http://productionserver'; break;
}

Then just open your browser console and type:

localStorage.setItem('env', 'testing');

You might not be able to open a console on mobile browsers or inside Cordova, but if you really need that: rethink the "same package" thing. I can't think of any valid reason why you would not want to do different testing and production builds.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top