开发者

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 (i.e 2 test cases) into the Test class. even methods without definition inside can do the trick

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜