【发布时间】:2011-03-22 16:07:57
【问题描述】:
我有一个简单的 HelloWorld Activity,我尝试使用 Android JUnit 测试对其进行测试。应用程序本身运行正常,但测试失败并显示
“java.lang.RuntimeException:无法解析活动:Intent { action=android.intent.action.MAIN flags=0x10000000 comp={no.helloworld.HelloWorld/no.helloworld.HelloWorld} } 在 no.helloworld.test.HelloWorldTestcase.setUp(HelloWorldTestcase.java:21)"
这是我的活动课:
包号.helloworld;
导入android.app.Activity;进口
android.os.Bundle;
公共类 HelloWorld 扩展 活动{
@Override
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
还有测试:
公共类 HelloWorldTestcase 扩展 ActivityInstrumentationTestCase2 {
private HelloWorld myActivity; private TextView mView; private String resourceString;
public HelloWorldTestcase() {
super("no.helloworld.HelloWorld", HelloWorld.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
myActivity = this.getActivity();
mView = (TextView) myActivity.findViewById(no.helloworld.R.id.txt1);
resourceString = myActivity
.getString(no.helloworld.R.string.helloworld);
}
public void testPreconditions() {
assertNotNull(mView);
}
public void testText() {
assertEquals(resourceString, (String) mView.getText());
}
protected void tearDown() throws Exception {
super.tearDown();
}
为什么测试失败? Activity(当然)在 AndroidManifest.xml 中定义,应用程序按应有的方式运行。
【问题讨论】:
标签: android exception junit android-activity android-intent