当前位置: 软件>java软件
AndroidJUnit4
本文导语: AndroidJUnit4 是一个让 JUnit 4 可以直接运行在 Android 设备上的开源工具。 示例代码: public class HelloActivity extends ActivityUnitTestCase { /** * For Eclipse with ADT */ public static junit.framework.Test suite() { ...
AndroidJUnit4 是一个让 JUnit 4 可以直接运行在 Android 设备上的开源工具。
示例代码:
public class HelloActivity extends ActivityUnitTestCase {
/**
* For Eclipse with ADT
*/
public static junit.framework.Test suite() {
// Should use AndroidJUnit4TestAdapter for to running AndroidDependent
// TestCases.
return new AndroidJUnit4TestAdapter(HelloActivity.class);
}
public static class MyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView view = new TextView(this);
view.setText("Hello, activity.");
view.setId(android.R.id.text1);
setContentView(view);
}
}
private Intent startIntent;
public HelloActivity() {
super(MyActivity.class);
}
@Override
@Before
public void setUp() throws Exception {
super.setUp();
startIntent = new Intent(Intent.ACTION_MAIN);
}
@Test
public void assertPreconditions() {
startActivity(startIntent, null, null);
assertNotNull(getActivity());
}
@Test
public void sayHello() {
startActivity(startIntent, null, null);
assertThat(((TextView) getActivity().findViewById(android.R.id.text1)).getText()
.toString(), equalTo("Hello, activity."));
}
}
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。