Test project setup in Android Studio

Test project setup in Android Studio

Android Studio supports testing for activities natively. Let’s see how you can set up your test environment:

  1. Open Android Studio and the Android project under test. You can create a blank project with a main activity and layout.
  2. Create the package where the tests will be saved. You can create the test package in the source folder: /src/main/java/<your_package>.tests.
  3. Create the running configuration for testing. Open the top menu Run and execute the Edit Configurations option. On the left side of the window, the list of running configurations is shown. You should at least have the running configuration for your Android Application. Click on the add button and select the Android Tests type:
    Android Tests Configuration
  4. Configure the package for testing. Select the recently created running configuration so you can edit it on the right side of the window. Do the following modifications:
    1. Write a name, for example My Tests.
    2. Select your app in the Module list.
    3. Check the All in package option to establish the whole package for testing.
    4. Select your test package in the Package input text.
    5. Check the Show chooser dialog option so later you can select the emulator or a real device connected via USB. If you prefer using always the USB device, change this option, as you like.
    6. Click on the OK button to save the changes and close the window.

    Test configuration

  5. Verify that the running configuration is available in the toolbar of Android Studio as is shown in the following screenshot.
    Configuration check
Share Button

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload the CAPTCHA.