views:

273

answers:

3

So, I'm new to android unit testing. I'm trying to write a unit test for the Phone application:

package com.android.phone;

import android.content.Intent;
import android.net.Uri;
import android.test.ApplicationTestCase;
import android.test.suitebuilder.annotation.MediumTest;

import com.android.phone.PhoneApp;

import dalvik.annotation.TestTargetClass;

@TestTargetClass(PhoneApp.class)
public class TestPhone extends ApplicationTestCase<PhoneApp> {

        public TestPhone() {
                super(PhoneApp.class);
        }

        private PhoneApp phone;

        @Override
        protected void setUp() throws Exception {
                super.setUp();
                phone = getApplication();
        }

        @MediumTest
        public void testDialerIsUp() {
                assertNotNull("Phone app does not exist", phone);
                // TODO add tests
        }

}

Then I start an emulator, wait till it boots up, and run those tests:

adb shell am instrument -e class com.android.phone.TestPhone -r -w com.android.phone.tests/android.test.InstrumentationTestRunner

And now I'm getting a junit.framework.AssertionFailedError: PhoneApp does not exist. What is wrong here, why isn't PhoneApp up?

A: 

You don't show the code for your PhoneApp. Did you derive a PhoneApp class from the android.app.Application class? Or are you expecting that there is just something called PhoneApp out there that you can test?

You will need to write an android.app.Application class as part of your project, if you expect to test something.

Or, perhaps, you are talking about something that I do not understand. That is always possible.

brione
This app is a part of android platform.
folone
It can be found, for example, here: http://www.netmite.com/android/mydroid/packages/apps/Phone/src/com/android/phone/PhoneApp.java
folone
A: 

How does this even compile with "PhoneApp.class" in it if you just stick to the SDK?

I know you can use Robotium to test existing apps though.

pjv
I don't just stick to the SDK. I've got the whole platform sources.
folone
A: 

The problem was actually in that I didn't create a proper Android.mk file. I've learnt lots of interesting stuff here.

folone