Unit tests for Android

I've recently started developing for Android.  I'm using IDEA Ultimate 9.0 for Mac OS X with the Android Support plugin version 1.0.2.  I love the plugin, which makes running and debugging Android apps work just like any other project.  The one thing I haven't been able to get working, though, is unit testing.  Here is what I have done so far:

1. Created a "tests" folder and marked it as "Test Sources" in the module settings.

2. Created a test class that extends AndroidTestCase.  It has a single test method, whose entire body is "assert(false);".

3. Created a launch configuration of type "Android Tests".  For the "Test" option, I selected "Class" and pointed it to my test class.

Now I select the Run command and... absolutely nothing.  No progress indicator to show it's running.  No test failure reported.  Nothing appears in the Logcat window.  Absolutely nothing happens to suggest the Run command hasn't been completely ignored.

What am I missing?

Peter

0
9 comments
Avatar
Permanently deleted user

Sorry, I don't have answer to your question. However I do want to ask you how you got Android support working on IDEA9?

On both Windows (trial) and Mac (full), my installation does not enumerate Android platforms. I'm primarily a Mac user. So, I'd appreciate your response since I'm not getting any response to a query I posted.

Couple of questions:

1. Did you install IDEA9 after you installed Android platform? (I've 2.1)
2. Where is your Android folder located? (I've under ~/Android)

Anything else you want to add.

Appreciate it.

Muthu

0
Avatar
Permanently deleted user

I installed the Android SDK under /Developer.  I installed the 2.0.1 platform and created a virtual device using the SDK tools.  I don't remember all the details of exactly what I did in IDEA, but I told it to create a new project from scratch of type "Android Module".  I think I had to tell it where the SDK was installed, though I don't remember exactly when I did that.

There's a "Getting Started" guide at http://code.google.com/p/idea-android/wiki/GettingStarted.  It's a bit out of date, so not all of the steps will be exactly as they describe, but it was good enough to get me going.

Peter

0
Avatar
Permanently deleted user

Thanks. I tried all that. No luck. I think I've tried everything on Google regarding
this.

0
Avatar
Permanently deleted user

Can it really be that no one is doing unit testing for Android?  This seems like such a basic feature.  Has anyone gotten it to work?

Peter

0
Avatar
Permanently deleted user

You have to create separate "test" module to run unit tests on the emulator or device. You can see samples in Android SDK, i.e. <sdk>/platforms/android-2.0/samples/HelloActivity. You need to create an IDEA module on its "tests" subfolder which should depend on the basic "HelloActivity" module. Then you will be able to create run configuration for the "tests" module.

0
Avatar
Permanently deleted user

Thanks!  I already had my tests in a separate module.  I copied over the AndroidManifest.xml from one of the SDK examples, changing it to have the correct packages for my project.  Here it is:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="net.sf.gamine.tests">
    <application>
        <uses-library android:name="android.test.runner" />
    </application>

  <instrumentation android:name="android.test.InstrumentationTestRunner"
      android:targetPackage="net.sf.gamine"
      android:label="Gamine tests">
  </instrumentation>

</manifest>

Now it gets further when I try to run the test case.  It seems to be running, but then tells me, "No tests were found."  Here is the content of the log:

Waiting for device.
Target device: emulator-5554 (2.0.1Device)
Uploading file
    local path: /Users/peastman/IdeaProjects/Gamine/out/production/Tests/Tests.apk
    remote path: /data/local/tmp/net.sf.gamine.tests
Testing started at 7:50 PM ...
Installing application.
DEVICE SHELL COMMAND: pm install "/data/local/tmp/net.sf.gamine.tests"
Application is already installed. Reinstalling.
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/net.sf.gamine.tests"
pkg: /data/local/tmp/net.sf.gamine.tests
Success

Test running failed: Unable to find instrumentation info for: ComponentInfo{net.sf.gamine.tests/android.test.AndroidTestRunner}
Running testsEmpty test suite.

I did a web search for the error message about, "Unable to find instrumentation info," but none of the hits seemed to match exactly what I'm seeing.  Any idea what the problem could be?

Peter

0
Avatar
Permanently deleted user

I got it!  Looking at the run configuration again, I noticed that IDEA had automatically filled in the test runner to use as "android.test.AndroidTestRunner".  I don't know why it did that, but the error about instrumentation made me think that might be the problem, since AndroidTestRunner doesn't support instrumentation.  So I cleared that field, and now it works.

Thank you!

Peter

0
Avatar
Permanently deleted user

(This has now been answered.)

0
Avatar
Permanently deleted user

peastman - thanks for posting this! I've got my first unit test running successfully in idea9 after following your basic steps.

Does Idea show you it's usual unit-test output? In order to determine if the test have passed for failed, I have to look through the android logs (the logcat tab) to look for any failed tests throwing an assertion.

0

Please sign in to leave a comment.