Configure Android Testing in IntelliJ 11

Had a heck of a time finding a tutorial on configuring Android instrumentation testing in IntelliJ. I tried the command line approach, but it was cumbersome and I’d rather have IDE integration. Finally I stumbled across this link which got me most of the way there. Some of the instructions are now automated in IntelliJ 11, so here’s an updated tutorial.

This tutorial assumes that you have installed the Android SDK, created an Android project, and simply want to add testing to it.

First, open project structure dialog by right clicking on project name or with the keyboard shortcut F4. Click the plus button and select “Module.”

IntelliJ Settings (Module) @coreylatislaw.com

Next, select “Create module from scratch” on the first screen of the wizard. Then choose a name and select “Android Module” type. Accept source directory settings on the next screen.
New Android Model. @coreylatislaw.com

Finally, select “Test” under “Project properties” and ensure the “Tested module” from the drop down list is correct. I like to set the “Target Device” to USB (New option! Note: Acts funky when two devices are plugged in. I filed a bug here). Finish the tutorial.
Android Test Configuration @coreylatislaw.com

Your project structure should look something like this:
Updated Project Settings. @coreylatislaw.com

When you exit, you will automatically have a run configuration for your new tests! Hit the play button and enjoy.
Run Tests! @coreylatislaw.com

5 thoughts on “Configure Android Testing in IntelliJ 11

  1. Nice tutorial. I am trying to setup a test module using robolectric. That seems to be difficult

Comments are closed.