Skip to content

End to End testing

Farees Hussain edited this page Jul 24, 2021 · 7 revisions

Overview

End-to-End tests in Oppia-android are written using UiAutomator. These tests are written under the instrumentation module which doesn't have Gradle support.

instrumentation/ -- android test binaries for each test suite.
`-- src -- AndroidManifest.xml to use the TestApplication from the java sourceset
    |-- java
    |   `-- org
    |       `-- oppia
    |           `-- android
    |               `-- instrumentation -- Test application and modules
    `-- javatest
        `-- org
            `-- oppia
                `-- android
                    `-- instrumentation -- Test suite for each part of the app

These tests are run using Bazel and ADB. Each Testsuite tests a particular part of the app, Each Testsuite has it's kt_android_library and android_binary.

How it works.

The android_binary of a test suite genarates a test apk with the same name as the class of the Test suite. this test apk is installed along with the original apk in the emulator. Now to run the test we use the adb am instrument command with this the adb shell opens the device or emulator, runs the tests and gives the test results.

How to run an End-to-End test

Prerequisites:

  1. To be able to build oppia using bazel
    bazel build oppia
    
  2. Add adb to the environment (platform-tools) i.e, add the following line to the .bashrc or the file path according to the Operating System.
    export PATH=/home/<username>/Android/Sdk/platform-tools:$PATH
    
  3. java version 8 (Optional, only for uiautomatorviewer)
    java -version
    
    output: openjdk version "1.8.0_292" OpenJDK Runtime Environment (build 1.8.0_292-8u292-b10-0ubuntu1~18.04-b10) OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)

Steps to run the tests:

  1. Build the BaseTest android_binary from the instrumentation module
    bazel build :oppia_test && bazel build //instrumentation:<test suite classname>
    
  2. install the oppia_test.apk and the ExplorationPlayerTest.apk
    adb install -r bazel-bin/oppia_test.apk && adb install -r bazel-bin/instrumentation/<test suite classname>.apk
    
  3. Run the instrumentation tests using am instrument command
    adb shell am instrument -w org.oppia.android.app.instrumentation/androidx.test.runner.AndroidJUnitRunner
    

How to create a new Testsuite

Writing tests for a new Testsuite involves creating a kt_android_library and a android_binary for the Testsuite

  1. Creating the kt_android_library for the testsuite in Build.bazel of "/instrumentation/src/javatest/org/oppia/android/instrumentation"
  2. Creating the android_binary for the testuite in Build.bazel of "/instrumentation/"
Clone this wiki locally