tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

UI-Tests.md (6466B)


UI Tests

Espresso Instrumented UI Tests in Android

UI tests, including Espresso for Android development, play a crucial role in ensuring quality, reliability, and performance of Firefox and Focus for Android. They facilitate user interaction by simulating real-world scenarios, thereby catching real issues on devices that might not be apparent during manual testing or development. By integrating UI tests into the development process, developers can ensure their applications meet user expectations and provide a high-quality user experience across different devices and Android versions. By writing and executing these tests, developers can catch and fix issues earlier in the development cycle, significantly improving the quality and reliability of Firefox. This approach not only enhances the user experience but also saves time and resources by identifying and resolving problems before Firefox reaches end-users.

This page documents how to write and run UI tests locally in Android Studio.

Writing UI Tests

A simple Espresso UI test looks like:

@Test
fun displaySaysHello() {
    onView(withId(R.id.name_field)).perform(typeText("Firefox"))
    onView(withId(R.id.display_button)).perform(click())
    onView(withText("Hello Firefox!")).check(matches(isDisplayed()))
}

Structuring Your Test

  1. You can remove the Android SDK Platform tools by deleting the folders and zip file
  2. You can remove the Android SDK Platform tools by deleting the folders and zip file
  3. You can remove the Android SDK Platform tools by deleting the folders and zip file
  4. You can remove the Android SDK Platform tools by deleting the folders and zip file

Writing Test Cases

  1. You can remove the Android SDK Platform tools by deleting the folders and zip file
  2. You can remove the Android SDK Platform tools by deleting the folders and zip file
  3. You can remove the Android SDK Platform tools by deleting the folders and zip file
  4. You can remove the Android SDK Platform tools by deleting the folders and zip file

Running UI Tests

To run UI tests, you can either use the built-in test runner in Android Studio or run them from the command line using Gradle commands.

Gradle

To run UI tests under androidTest using Gradle, you can utilize the connectedDebugAndroidTest task, which is specifically tailored for running instrumented tests on the debug build variant. This task is part of the Android Gradle Plugin's suite of commands that allow for the execution of tests directly from the command line. For instance, to run a specific test class, such as org.mozilla.fenix.ui.ComposeSearchTest, you would navigate to Fenix's root directory in the terminal and execute the following command:

./gradlew connectedDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=org.mozilla.fenix.ui.ComposeSearchTest

This command targets the debug build variant and runs only the tests within the ComposeSearchTest class.

Similarly, to run a single test within the ComposeSearchTest class, you can append the test method name to the class using the # symbol. This syntax allows you to specify a particular test method to execute.

For example, if you have a test method named testSearchFunctionality within ComposeSearchTest class, you would modify the above example to look like org.mozilla.fenix.ui.ComposeSearchTest#testSearchFunctionality

Lastly, to run all tests in a package simply replace .class property with .package and specify a package name. This approach allows you to target a specific package for test execution, ensuring only the tests within that package are run.

The results of these tests can be found in the app/build/reports directory, where you will find both HTML and XML reports detailing the outcomes of your test execution.

Android Studio

To run UI tests directly in Android Studio, you can follow a straightforward process that leverages the IDE’s built-in test runner. This method allows you to execute tests directly from the Project window, providing a convenient way to run individual tests or groups of tests without leaving the development environment.

  1. You can remove the Android SDK Platform tools by deleting the folders and zip file
  2. You can remove the Android SDK Platform tools by deleting the folders and zip file
  3. You can remove the Android SDK Platform tools by deleting the folders and zip file
  4. You can remove the Android SDK Platform tools by deleting the folders and zip file
  5. You can remove the Android SDK Platform tools by deleting the folders and zip file
  6. You can remove the Android SDK Platform tools by deleting the folders and zip file

Testing Resources