标签:
Robotium环境搭建与新手入门教程
01 |
package com.example.android.notepad.test; |
02 |
03 |
import android.test.ActivityInstrumentationTestCase2; |
04 |
05 |
import com.example.android.notepad.NotesList; |
06 |
import com.jayway.android.robotium.solo.Solo; |
07 |
08 |
public class NotePadTest extends ActivityInstrumentationTestCase2 |
09 |
{ |
10 |
private Solo solo; //声明Solo |
11 |
public NotePadTest() //构造方法 |
12 |
{ |
13 |
super (NotesList. class ); |
14 |
15 |
} |
16 |
17 |
@Override |
18 |
public void setUp() throws Exception |
19 |
{ |
20 |
solo = new Solo(getInstrumentation(), getActivity()); |
21 |
} |
22 |
23 |
@Override |
24 |
public void tearDown() throws Exception |
25 |
{ |
26 |
solo.finishOpenedActivities(); |
27 |
} |
28 |
29 |
public void testAddNote() throws Exception |
30 |
{ |
31 |
//点击add note按钮 |
32 |
solo.clickOnMenuItem( "Add note" ); |
33 |
//比对结果 |
34 |
solo.assertCurrentActivity( "Expected NoteEditor activity" , "NoteEditor" ); |
35 |
//在第一个TextEdit控件上输入内容 |
36 |
solo.enterText( 0 , "Note 1" ); |
37 |
//返回上个界面 |
38 |
solo.goBack(); |
39 |
//点击菜单中的Add note |
40 |
solo.clickOnMenuItem( "Add note" ); |
41 |
//在第一个EditText中输入内容 |
42 |
solo.enterText( 0 , "Note 2" ); |
43 |
//返回NotesList activity |
44 |
solo.goBackToActivity( "NotesList" ); |
45 |
//截屏 |
46 |
solo.takeScreenshot(); |
47 |
boolean expected = true ; |
48 |
boolean actual = solo.searchText( "Note 1" ) ; solo.searchText( "Note 2" ); |
49 |
assertEquals( "Note 1 and/or Note 2 are not found" , expected, actual); |
50 |
51 |
} |
52 |
53 |
} |
标签:
原文地址:http://www.cnblogs.com/AmilyWilly/p/4661393.html