TA的每日心情 | 擦汗 2015-2-4 16:27 |
---|
签到天数: 6 天 连续签到: 1 天 [LV.2]测试排长
|
3#
楼主 |
发表于 2015-1-8 10:10:10
|
只看该作者
就是用Robotium框架写了一个关于eclipse自带例子NotePad的测试用例,测试用例代码如下:
package com.example.android.notepad.test;
import junit.framework.Assert;
import com.robotium.solo.Solo;
import android.app.Activity;
import android.app.Instrumentation;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
public class NotePadTest extends ActivityInstrumentationTestCase2 {
private static final String Launcher_Avtivity_Full_ClassName = "com.example.android.notpad.NotesList";
private static Class<?> launcherActivityClass;
private Solo solo;
private Activity activity;
private Instrumentation inst;
static {
try{
launcherActivityClass = Class.forName(Launcher_Avtivity_Full_ClassName);
}catch (ClassNotFoundException e){
throw new RuntimeException(e);
}
}
public NotePadTest() {
super(launcherActivityClass);
}
protected static void setUpBeforeClass() throws Exception {
}
protected static void tearDownAfterClass() throws Exception {
}
public Activity getActivity(){
return super.getActivity();
}
protected void setUp() throws Exception {
inst = getInstrumentation();
solo = new Solo(inst,getActivity());
super.setUp();
}
protected void tearDown() throws Exception {
solo.finishOpenedActivities();
super.tearDown();
}
public void testAddNote(){
solo.sleep(3000);
View menuadd = solo.getView("menu_add");
solo.clickOnView(menuadd);
solo.sleep(2000);
solo.enterText(0, "Note1");
solo.sleep(2000);
View menusave = solo.getView("menu_save");
solo.clickOnView(menusave);
ListView list = (ListView)solo.getView("list");
TextView tv = (TextView)solo.getView("tv");
Assert.assertEquals(true, tv.getText().equals("Note1"));
}
public void testdeleteNote(){
ListView list = (ListView)solo.getView("list");
int beforecount = list.getChildCount();
Log.d("debug", "beforeCount:"+beforecount);
solo.sleep(2000);
solo.clickOnView(list.getChildAt(0));
solo.clickOnText("delete");
solo.sleep(3000);
int aftercount = list.getChildCount();
Log.d("debug", "beforeCount:"+aftercount);
Assert.assertEquals("删除笔记后数目没有减少", 1,beforecount-aftercount);
}
}
Run as android JUnit Test控制台就会报这个错误:
Test run failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException'。
|
|