
- Espresso Testing Framework Tutorial
- Espresso Testing - Home
- Introduction
- Setup Instructions
- Running Tests In Android Studio
- Overview of JUnit
- Architecture
- View Matchers
- Custom View Matchers
- View Assertions
- View Actions
- Testing AdapterView
- Testing WebView
- Testing Asynchronous Operations
- Testing Intents
- Testing UI for Multiple Application
- Test Recorder
- Testing UI Performance
- Testing Accessibility
- Espresso Testing Resources
- Espresso Testing - Quick Guide
- Espresso Testing - Useful Resources
- Espresso Testing - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Running Tests In Android Studio
In this chapter, let us see how to run tests using Android studio.
Every android application has two type of tests −
Functional / Unit tests
Instrumentation tests
Functional test does not need the actual android application to be installed and launched in the device or emulator and test the functionality. It can be launched in the console itself without invoking the actual application. However, instrumentation tests need the actual application to be launched to test the functionality like user interface and user interaction. By default, Unit tests are written in src/test/java/ folder and Instrumentation tests are written in src/androidTest/java/ folder. Android studio provides Run context menu for the test classes to run the test written in the selected test classes. By default, an Android application has two classes − ExampleUnitTest in src/test folder and ExampleInstrumentedTest in src/androidTest folder.
To run the default unit test, select ExampleUnitTest in the Android studio, right-click on it and then click the Run 'ExampleUnitTest' as shown below,

Run Unit Test
This will run the unit test and show the result in the console as in the following screenshot −

Unit Test Success
To run the default instrumentation test, select ExampleInstrumentationTest in the android studio, right-click it and then click the Run 'ExampleInstrumentationTest' as shown below,

Run Instrumentation Test
This will run the unit test by launching the application in either device or emulator and show the result in the console as in the following screenshot −

The instrumentation test ran successful.