Android unit-testing support

With IntelliJ IDEA X you can write unit tests for your Android application using Android Testing Framework. Android unit tests are located in a separate test module, so first you need to add it (i.e. named tests) to your project, which must already contain an Android module (or module with Android facet) (i.e. named MyAndroidApp). Then, specify this tested module:

IntelliJ IDEA will automatically create a sample test class for your main activity (i.e. MyActivityTest). It’s handy that you can launch tests directly from editor. Note that it is important to choose an item with Android-specific icon for launching tests by Android Tests run configuration rather than using a default JUnit configuration:

Also, after adding a test module to project, IntelliJ IDEA automatically creates run configuration for launching all tests in module:

Note, that scope of a dependency between Test module and Application module should be Provided.

This entry was posted in New Features and tagged , , . Bookmark the permalink.

6 Responses to Android unit-testing support

  1. p-daddy says:

    Hi,

    I just purchased the ultimate version of intellij and I’m still not quite understanding how to add the android testing framework to my android project

    Specifically, looking at your screenshots above, there is a window (the picture is called test-module) where you specify the the SDK and you can then (in the same window) specify “Application”, “Library” or “Test”.

    When I create a new module within my Android application, I don’t see this option (“application”, “library”, or “test”)

    Is there a more step-by-step guide on how to set up testing for android?

  2. yole says:

    The Android testing support is a new feature of IntelliJ IDEA X, which is currently in development and available as Early Access Preview. It’s not available in IntelliJ IDEA 9.

  3. Cam says:

    How does this work in IntelliJ 11? Screens are very different when creating a module.:)

    Thanks

    Cam

  4. Eugene Kudelevsky says:

    @Cam of course, it works in IDEA 11. If something doesn’t work for you, please create an issue in our tracker

  5. Evgen says:

    I have a Android maven project could you give me some hints about right way to add Andorid unit-testing to my project? I have IDEA 11.

  6. John Matthews says:

    I am using IDEA 12.0.4 Ultimate and when I use the wizard to create new Android Test Project, it starts to create one and then errors with this:

    The project wasn’t generated by ‘android’ tool.

    Error: No AndroidManifest.xml file found in the main project directory: C:WorkspacesIntelliJ12application

    Not sure why… but the project I am using is a couple of android applications and Java libraries put into one. The error showing the directory isn’t the directory I was pointing to its at C:WorkspacesIntelliJ12applicationdata

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>