Back to Resources

Blog

Posted November 9, 2022

Appium vs. Espresso

Learn the differences between Appium and Espresso for mobile app testing.

quote

Are you building a mobile application and want to automate UI testing, but don’t know where to start? If so, you’re not alone. There are many ways to perform UI testing for mobile apps.

In this post, I’ll provide some direction by discussing the pros and cons of two of the more popular tools for mobile app testing: Appium and Espresso.

Appium vs Espresso: Key Differences

Appium and Espresso are both test automation tools for mobile app testing. The biggest difference is that Espresso can test only Android applications, while Appium can test both Android and iOS applications.

Also unlike Appium, Espresso code expects to run on the same machine as the device under automation. The Espresso API is either compiled into the app under automation or installed side-by-side. Espresso integrates with Android Studio, however, Espresso code must be written in either Java or Kotlin.

Appium can use Espresso as the driver in an Android test, allowing it to make use of Espresso’s close integration with the device UI, while offering all the advantages of language independence and client/server architecture. This comes at the cost of slower tests, as Appium introduces an additional layer between automation code and device.

What is Appium?

Appium is one of the leading tools for controlling a native, hybrid, or mobile app on iOS mobile, Android mobile, and Windows desktop platforms. It allows testers and developers to create automated tests of mobile applications, helping them deliver quality software faster, with less risk.

Appium is a freely available, open-source tool. This means anyone can use it, read the source code, and contribute new features and suggestions. This has helped Appium become one of the most popular mobile automation tools, used by software teams worldwide.

The Appium project believes that app automation should be possible from any language or framework, and should work without requiring specific changes to the app code.

Read more on the Appium documentation.

Appium Benefits

  • Built on the same JSON wire protocol as Selenium, which means QA and development professionals who are familiar with Selenium should find the transition to Appium fairly seamless.

  • Allows for testing of native, mobile web and hybrid apps, and can be run across both the iOS and Android operating systems.

  • Tests are language-agnostic and users do not need to install any extra software on their mobile device to support Appium.

  • Backed by a large and thriving community that provides users with consistent support and troubleshooting.

  • Choose your own underpinning framework, like XCTest or XCUITest, for unit testing.

  • Cross-platform support allows for reuse of test scenarios across mobile and web channels.

  • Write tests with your favorite tools using any WebDriver-compatible language such as Java, Objective-C, and JavaScript.

  • The entire framework is open source.

  • Appium is the de facto standard for WebDriver development on iOS.

Appium Disadvantages

  • Users who are new to Appium need to familiarize themselves with a new scripting language and learn the rules on how to best interrogate your application to see the benefits of automated testing.

  • Requires users to learn the concepts of native app/ selectors and have a reasonable understanding of the Appium architecture, which adds to the learning curve.

  • Appium relies on a cascade of open source components; each must be installed in a version that supports the others.

Example Appium Test Scripts

These Appium scripts for iOS and Android mobile app tests on emulators and simulators can help streamline your testing process. Below are links to the Sauce Labs Training on GitHub repository, where you'll find demo scripts for a variety of use cases to get you started with automated Appium testing:

What is Espresso?

Espresso is the testing framework that comes built into Android Studio; it is designed specifically for functional testing of Android applications.

Espresso Benefits

  • Comprehensive framework for automated UI testing of Android apps

  • Allows for faster test execution with automatic synchronization of the UI

  • Intuitive to work with for Android developers as it's based on Java/Kotlin

  • Accelerates developer feedback by allowing compilation of tests into a separate APK

  • Reduces test flakiness and produces reliable test results

  • Simple to set up as works well within the Android Studio IDE

  • Allows developers to monitor internals of the device for finer control

  • Easy to maintain and customize Android UI tests with Espresso APIs

Espresso Disadvantages

  • Only compatible with Java and Kotlin, meaning that your tests can only be written in these languages.

  • Can only be used to test Android apps, so if your team is developing an app that will be listed on both iOS and Android, you will need to find another framework to help ensure compatibility across these different operating systems.

Espresso Test Case

It’s easy to get up and running with Espresso if you already have an Android application started. But as with all testing frameworks, it can be complicated as you try to do more.

Inside the mobile application, update your gradle.build file to have the proper dependencies, and load the test runner.

Sample gradle.build file with the new parts in bold:

1
apply plugin: 'com.android.application'
2
3
android {
4
compileSdkVersion 22
5
buildToolsVersion "22"
6
7
defaultConfig {
8
applicationId "com.my.awesome.app"
9
minSdkVersion 10
10
targetSdkVersion 22.0.1
11
versionCode 1
12
versionName "1.0"
13
14
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15
}
16
}
17
18
dependencies {
19
// App's dependencies, including test
20
compile 'com.android.support:support-annotations:22.2.0'
21
22
// Testing-only dependencies
23
androidTestCompile 'com.android.support.test:runner:0.5'
24
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
25
}
  • Next, create the test class, which will see if the words “Hello World” are displayed on the screen.

1
@RunWith(AndroidJUnit4.class)
2
@LargeTest
3
public class HelloWorldEspressoTest {
4
5
@Rule
6
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule(MainActivity.class);
7
8
@Test
9
public void listGoesOverTheFold() {
10
onView(withText("Hello world!")).check(matches(isDisplayed()));
11
}
12
}
  • Execute the tests.

$ ./gradlew connectedAndroidTest

That’s it! You now have Espresso running a test.

See the Sauce Labs docs for more information on how to configure your Espresso tests.

Appium vs. Espresso: Which is Right for You?

While both Appium and Espresso can fill the need for UI testing for your Android application, it really comes down to the scope of your testing. Ideally, you could leverage both frameworks to maximize the amount of testing done to the application, but as with most things, that is more time than most people have to invest upfront.

If you’re selecting just one framework, then for developers building a native Android application that have their scope limited to just the app and want comprehensive and embedded UI testing, Espresso will definitely fill that need.

If the tests need to support multiple platforms (e.g., iOS, hybrid, and Android), and you need to validate how the app reacts to outside factors like screen rotation, and/or you want to run the testing in parallel using an automated testing solution like Sauce Labs, then Appium will better meet your needs.

Getting Started with Sauce Labs Mobile App Testing

Sign up for a free Sauce Labs trial and experience the benefits of mobile testing in the Sauce Labs cloud. Test your mobile apps across the most comprehensive range of real devices (iPhone, iPad, Samsung Galaxy, Google Pixel, Xiaomi, and more), emulators, and simulators to increase coverage and release with speed and confidence.

© 2023 Sauce Labs Inc., all rights reserved. SAUCE and SAUCE LABS are registered trademarks owned by Sauce Labs Inc. in the United States, EU, and may be registered in other jurisdictions.