Sar*_*ara 3 junit android exception android-intent android-activity
我有一个简单的HelloWorld Activity,我尝试使用Android JUnit测试进行测试.应用程序本身就像应该运行一样,但测试失败了
"java.lang.RuntimeException:无法在no.helloworld.test上解析:Intent {action = android.intent.action.MAIN flags = 0x10000000 comp = {no.helloworld.HelloWorld/no.helloworld.HelloWorld}}的活动. HelloWorldTestcase.setUp(HelloWorldTestcase.java:21)"
这是我的活动课程:
包装no.helloworld;
import android.app.Activity; 进口
android.os.Bundle;
公共类HelloWorld扩展Activity {
@覆盖
Run Code Online (Sandbox Code Playgroud)public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }
而且测试:
公共类HelloWorldTestcase扩展ActivityInstrumentationTestCase2 {
Run Code Online (Sandbox Code Playgroud)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();
}
Run Code Online (Sandbox Code Playgroud)
为什么测试失败?该活动(当然)在AndroidManifest.xml中定义,应用程序按预期运行.
| 归档时间: |
|
| 查看次数: |
2854 次 |
| 最近记录: |