Skip to main content

Android unit tests


You can perform unit tests using the Android Unit Test Step, and view the results in the Test Reports Add-on.

Running a unit test

Unit tests are useful if you want to verify individual code blocks, catch bugs or prevent crashes as early as possible.

This tutorial tells you how to run a unit test against your app and how to generate test reports using your primary workflow.

Luckily, your Android primary workflow already contains the Android Unit Test Step which is responsible for performing unit test on your build.

Using custom steps/scripts

If you use custom steps or scripts, our Deploy to Step by default deploys files/build artifacts from the $BITRISE_DEPLOY_DIR directory, so make sure that you move the generated app there.

Alternatively, set the deploy directory or the file path input of the step to point to the location of the files/build artifacts.

Please note, that if the specified path is a directory, then every file in that directory will be deployed. If there are subdirectories in the specified directory, they won’t get uploaded! You can upload a directory’s content recursively, if you use the Compress option, which will compress the whole directory including every subdirectory. And finally, if you specify a file path, then only the specified file will get deployed.

Check your logs in the case of failed builds

If your build has failed, click on Download logs on your Build’s page. In the last lines of your Step log, you can view the error message and fix the error accordingly. If you’re done, commit your changes to your repository, and a new build should start automatically.

Generating and checking test results

You can check your Android unit test results on the Test Reports page. The Android Unit Test Step generates and exports unit test reports into the $BITRISE_TEST_DEPLOY_DIR folder. Then the Deploy to  Step exports those reports from the $BITRISE_TEST_DEPLOY_DIR folder to the respective build’s Test Reports page where you can view the test results.

Step versions supporting Test Reports

The Deploy to Step must be of version 1.4.1 or newer and the Android Unit Test Step must be of version 0.10.0 or newer since older versions of the Steps do NOT support Test Reports.

Checking test results

Test Reports display the most important information about all the tests you ran on the Test Summary tab. You will see all the tests you ran, their duration, and their results. You can also click on the tabs of the individual tests to see their details.

To access the result of a particular test:

  1. Find your app on the Dashboard, and select it.

  2. On the app's main page, select the build you want to check out.

  3. Go to the Details & Add-ons tab.

  4. Select Test Reports.

  5. On the Test Summary tab, find the test you want to check. Alternatively, on the top bar, click the tab of the test set you want to check out.To filter tests based on their results, open the menu on the top right, which is set to All by default.

    Test Reports
  6. Click Test cases to see the details.

    UI tests are grouped according to device while unit tests are grouped according to test cases.

You will find:

  • The total number of tests you ran, as well as the ratio of successful and failed tests.

  • The duration of each individual test (both unit tests and UI tests).

  • In the case of UI tests, the orientation and the locale of the device.

    Test Reports

You can check, depending on the test type:

  • Individual test cases

  • Performance data

  • Videos

  • Screenshots

  • Test artifacts

  • Logs

As noted above, this depends on test type, too: for unit tests, you won’t see screenshots or videos, of course.