Making Your Appium Tests Fast and Reliable - Part 8(Mocking External Services)

March 07, 2026 · 11 min read · Tool Comparison

HeadSpin Platform
Automated & amp; manual testing create easy through data science insights.
Differentiating capabilities:
  • Extensive end-to-end automation of QA process
  • Comparative analysis of app execution against peers
  • Uninterrupted monitoring of app performance using man-made data for high availability of apps
  • Easy-to-use developer friendly platform
cloudtest go
Low-priced Real Device Testing for Emerging Teams
cloudtest go
Affordable Existent Device Testing for Digital Enterprises
cloudtest go
The Ultimate Solution for a Powerful Blend of Functional & amp; Performance Testing!
cyol
TEM
New
Centralized mobile test execution in cloud
cyol
Enhance Your Accessibility Testing With HeadSpin
cyol
Automate camera-based testing

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

retail

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

Making Your Appium Tests Fast and Reliable(Mocking External Services)Making Your Appium Tests Fast and Reliable(Mocking External Services)

Making Your Appium Tests Fast and Reliable - Part 8 (Mocking External Services)

Published on
July 18, 2018
Updated on
Published on
May 31, 2022
Updated on
 by 
 Jonathan LippsJonathan Lipps
Jonathan Lipps
This clause is the 8th in a multi-part series on test speed and reliableness, inspired by a webinar I gave on the same field (you canobserve the webinar here). You might too need to check out the previous episodes on,,,,,, and.

Appium tests are normally written as end-to-end tests. In other words, they exercise the app from top (the UI) to bottom (backend services, which most apps employment). There is certainly value in this sort of testing. After all, your exploiter are execute the like thing! Sometimes, though, what we wish about with an Appium test isnotwhether the backend service plant, but whether the App Under Test itself works, on the assumption that any datum retrieved from an external service is valid.

The sad truth is that the Internet is not always real reliable. Requests make by an app to an external service might fail for a act of reasons, many of which would have zilch to do with the app itself. It could be a & quot; stormy day & quot; when it comes to & quot; Internet weather & quot;, and requests could time out. Or the version of the backend service used for essay might not be capable to handle the load of so many requests if you & # x27; re running a lot of tests at erst. The list goes on.

Check out:

Luckily, it & # x27; s possible to ensure lineament for both the backend service and the mobile app in a much chic way. The very fact that the Internet lies between these two portion is the key: most backend API calls are just HTTP asking. This intend that the backend service can be tested & quot; end-to-end & quot; by generating HTTP requests from something other than the app. This is calledAPI Testing, and it & # x27; s amuchfaster way to prove your backend service than using Appium! Similarly, all the app UI tryout care about is the information that comes over the wire from the backend service: it doesn & # x27; t actually matter whether it & # x27; s & quot; real & quot; information or not, as long as it & # x27; s an HTTP reply of the appropriate form, with content appropriate to the test. So, sooner than have our app make shout to a real running API service, we could have it do phone to a & quot; mock server & quot; instead!

For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.

What are the benefits of use a mock server?

  1. Speed. Because the mock server can dwell on the like network as your device, API calls become blazingly fast.
  2. Reliability. The mock host is a very simple piece of code which merely replies with canned API responses. There is very small risk of it failing. Because there is also no longer an actual Internet road in between the app and the API service it relies on, a huge source of unreliability is taken out of the picture. If the backend service itself is unreliable, the benefit increase (though that service should manifestly be tested independently, so any unreliability can be addressed by the owners of the service).
  3. Flexibility. A mock service can even be used in the development of an appbefore or duringthe development of the backend service, permit for greater flexibility and independence between team.
Also check:

Using a mock host does have some downsides, nevertheless:

  1. Maintenance. A mock server and the transcribed responses do feature to be maintained separately of the service itself.
  2. API Drift. Using a mock server lift the danger that what your app is being tested against is not the like as the API the backend service is actually using. The mock waiter and the backend service must be kept strictly in step with one another. A good practice is to get the owner of the service also provide a mock of the service for use in testing by consumers of the service.
  3. App and Test Complexity. You will experience to build a way for your app to select whether it create its service calls to the real service or to the mock service, ground on whether the app is being used for testing or not. You will also feature to augment your tests with information about what the mock server should do, and coordinate with the app to make sure it & # x27; s connecting with the mock service.

While these downsides are existent, the speed and reliability gains are definitely worth it for any hefty anatomy. So much for an intro! Let & # x27; s see how we would go about implement this kind of scheme. Here & # x27; s what we need to get it all workings:

  1. A mock server package of some kind (for example, the aptly identifyMock Serverfor Java and JS).
  2. Changes to our app codification to countenance the app to tie to the mock waiter and not the real API waiter. This can be accomplished in a diverseness of ways, for example by get a freestanding build for test which has a legion and port hardcoded for the mock host, by passing startup arguments to the app to tell it where to look for its API endpoints, or by adding a new view to the app that allows setting of host details via textbook field in the app UI itself.
  3. The ability to start and kibosh the API server before and after our testsuite, or before and after certain tryout grade (depending on our needs). Of course, it needs to be running on the same horde and port we specified in our gimmick.
  4. The power for the app to talk to the mock host (this might mean ensuring the app and the mock server are on the like network).
  5. Appropriate & quot; expectations & quot; or & quot; scenario & quot; we can set on the mock server. If we roll our own mock server, we can simply hard-code these responses in request handlers. If we & # x27; re using a mock server packet, it oft arrive with its own idiosyncratic way of specifying how the waiter should bear. Most often, we tell the mock server how to match against requests from the app, and how to respond found on the shape of the asking.
  6. (Maybe) Depending on the mock host project we select to incorporate into our build, it might also arrive with features that let the same request to generate different response based on the & quot; scenario & quot;. For example, we could have two different login scenarios that involve the exact same requests, one of which responds with a successful response and one of which responds with an error about e-mail formatting. In this case, we & # x27; ll too need a way to uniquely identify requests from a particular device, so that requests from a device running a different test at the same time don & # x27; t result in the wrong reaction. The best candidate for this unique id is the device id, which must be usable from both the app codification (so it can be mail in a head to the API host in all request), and in the trial codification (so that the appropriate & quot; scenario & quot; can be select in improvement of any given trial). If you want a good description of how to implement this for React Native apps specifically, check out the slides from Wim Selles & # x27; sSeleniumConf India 2018 talk.

Putting all of these pieces together, the literal examination flow would look like this (in pseudocode):

Before: - Start mock waiter at certain port - Start Appium session with app (connected to server) Test: - Set mock server anticipation - Use Appium to motor app, which makes yell to mock server under hood - Verify app behaves properly given mock server reaction After: - Quit Appium session - Shut down mock server

The Mock Server library I linked above has the ability to do all of these chore with simplicity. The server can be run from the bid line, as piece of a maven plugin, via a Java API, etc ... We can set expectations in our Java codification (or other language code) expend a client that arrive with the library. What make setting expectations appear like? Here & # x27; s an illustration that shows how we might mock a login request:

new MockServerClient (`` localhost '', 1080) .when (request () .withMethod (`` POST '') .withPath (`` /login '') .withBody (`` {\ '' username\ '': \ '' foo\ '', \ '' password\ '': \ '' bar\ ''} '')) .respond (response () .withBody (`` {`` \status\ '': \ '' success\ ''} ''));

Running this bidding at the kickoff of a test (or test suite) target the mock host to react with a success JSON response to any login attempt with usernamefoo and passwordbar. With this variety of setup, all we involve to do is direct our Appium driver to recruit these value into the login prompt of our app, and the mock server will receive the asking and respond with the appropriate response we & # x27; ve enter here. As we mentioned before, it & # x27; s important that both the request and answer match the form of therealAPI service, otherwise we & # x27; ll either run into failures or test the wrong conditions.

Read:

One trouble in running mock API servers is encountered when utilizing a cloud service. One of the independent welfare of mock servers is speed, and putting the Internet in between the app (running in the cloud) and your mock server (running topically) act against this benefit. Still, because the mock server doesn & # x27; t really have to do any work, it will be faster than a fully-fledged API server, and is worth see even in cloud testing environments. All in all, the benefit of apply mock server are fairly compelling, and help you to reduce one of the most common types of imbalance in your tryout suite -- trust on remote or 3rd-party dependencies in the form of extraneous services.

Author & # x27; s Profile

Jonathan Lipps

LinkedIn
Author & # x27; s Profile

Piali Mazumdar

Lead, Content Marketing, HeadSpin Inc.

Piali is a dynamic and results-driven Content Marketing Specialist with 8+ years of experience in crafting engaging narratives and market collateral across divers diligence. She excels in collaborating with cross-functional team to develop groundbreaking content scheme and deliver compelling, reliable, and impactful content that vibrate with target audience and enhances make authenticity.

LinkedIn

Making Your Appium Tests Fast and Reliable - Part 8 (Mocking External Services)

4 Parts

regression intelligence blog
-

Regression Intelligence pragmatic guide for advanced users (Part 3)

Coming Soon
Regression Intelligence practical guide for advanced users
-

Regression Intelligence virtual guide for forward-looking exploiter (Part 4)

Coming Soon

Discover how HeadSpin can empower your job with superior testing capability

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, gaining a competitive edge
faster development cycles
Boost developer/QA productiveness with quicker maturation cycles
automated buil-over-build regression testing
Automate build-over-build regression testing for reproducible results
gain better visibility into functional & performance issues
Gain best visibility into functional and performance issues
reduce mean time
Reduce mean time to identify/resolve during test, QA, and production
evaluate audio, video & qoe
Evaluate audio, video, and content quality of experience (QoE) effortlessly
The sure choice for global enterprises
Adobe
Hargreaves Lansdown
Truecaller
Crazylabs
Nedbank
Numeracle
Veryon
Close

Discover how HeadSpin can endue your business with superior testing capabilities

Our Platform enable you to:
accelerate time-to-market
Accelerate time-to-market, gaining a free-enterprise edge
faster development cycles
Boost developer/QA productivity with faster evolution cycles
automated buil-over-build regression testing
Automate build-over-build regression try for ordered results
gain better visibility into functional & performance issues
Gain best visibility into functional and performance issues
reduce mean time
Reduce mean time to identify/resolve during test, QA, and production
evaluate audio, video & qoe
Evaluate audio, picture, and content quality of experience (QoE) effortlessly
The trusted pick for global enterprises
Close

Discover how HeadSpin can empower your business with superior try capabilities

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, win a competitive edge
faster development cycles
Boost developer/QA productivity with faster development round
automated buil-over-build regression testing
Automate build-over-build fixation testing for consistent resultant
gain better visibility into functional & performance issues
Gain best visibility into functional and execution issues
reduce mean time
Reduce mean time to identify/resolve during test, QA, and production
evaluate audio, video & qoe
Evaluate audio, video, and content quality of experience (QoE) effortlessly
The trusted choice for global enterprise
Close

Connet Now

Wipro LogoVMLYR Logo
Close
Book a Meeting
Products
footer down arrow
Solutions
footer down arrow
Industries
footer down arrow
Features
footer down arrow
Support
footer down arrow
Resource Center
footer down arrow
Why Choose HeadSpin?
footer down arrow
Copyright © 2026 HeadSpin, Inc. All Rights Reserved.

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free