简体   繁体   中英

Problems with running Android Activity unit-testing from Eclipse

Im having a problem starting or running any activity unit tests from within eclipse.

Even i start a clean project and make a simple test class it always prints to the console:

[2010-10-05 13:10:24 - testAndroid] Collecting test information
[2010-10-05 13:10:25 - testAndroid] Test run failed: Test run incomplete. Expected 2 tests, received 0

Any ideas ?

Just for testing, I have created a fresh Android project called Demo with a test project called DemoTest

The main activity to test is called Main and I have created a simple testclass MainTest that looks like this:

package net.demo.test;
import android.test.ActivityInstrumentationTestCase2;
import net.demo.Main;

    public class MainTest extends ActivityInstrumentationTestCase2<Main>
    {

        public MainTest()
        {
            super("net.demo", Main.class);
            // TODO Auto-generated constructor stub
        }
    }

My tests used to run fine before, but suddenly I cant run any of them, they all fail with the same error, even I create new a project. It seems like it something to do with Eclipse or and not with the Code.

Update: Seems like extending SingleLaunchActivityTestCase<Main> is working, but still got no clue about how to make ActivityInstrumentationTestCase2<Main> working.

I had no regression problems. I just couldn't get the example to work. I finally fixed it by defining two constructors:

public MainActivityTest(String pkg, Class<MainActivity> activityClass) {
    super("com.myapp", MainActivity.class);
}

public MainActivityTest() {
    super("com.myapp", MainActivity.class);
}

It turned out that most emulators before 2.3.3 were silently swallowing the error generated when construction went wrong.

You must put at least 2 methods (ie 2 test cases) into the Test class. even methods without definition inside can do the trick

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM