[英]Problems with running Android Activity unit-testing from Eclipse
Im having a problem starting or running any activity unit tests from within eclipse. 我在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 仅仅为了测试,我创建了一个名为Demo的全新Android项目,其中包含一个名为DemoTest的测试项目
The main activity to test is called Main and I have created a simple testclass MainTest that looks like this: 要测试的主要活动叫做Main,我创建了一个简单的测试类MainTest,如下所示:
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.
它似乎与Eclipse有关,而与Code无关。
Update: Seems like extending SingleLaunchActivityTestCase<Main>
is working, but still got no clue about how to make ActivityInstrumentationTestCase2<Main>
working. 更新:似乎扩展
SingleLaunchActivityTestCase<Main>
正在运行,但仍然不知道如何使ActivityInstrumentationTestCase2<Main>
工作。
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. 事实证明,2.3.3之前的大多数仿真器都默默地吞下了构造出错时产生的错误。
You must put at least 2 methods (ie 2 test cases) into the Test class. 您必须将至少2个方法(即2个测试用例)放入Test类中。 even methods without definition inside can do the trick
即使没有内部定义的方法也可以做到
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.