/
MainActivityInstrumentedTest.java
106 lines (82 loc) · 2.8 KB
/
MainActivityInstrumentedTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package com.rhino.unittesting;
import android.content.Intent;
import android.support.test.rule.ActivityTestRule;
import android.util.Log;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
/**
* @author LuoLin
* @since Create on 2018/6/7.
*/
public class MainActivityInstrumentedTest {
@Rule
public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<MainActivity>(MainActivity.class) {
@Override
protected Intent getActivityIntent() {
Intent intent = new Intent();
intent.putExtra("url", "http://www.baidu.com");
return intent;
}
@Override
protected void beforeActivityLaunched() {
super.beforeActivityLaunched();
Log.d("RHINO", "beforeActivityLaunched");
}
@Override
protected void afterActivityLaunched() {
super.afterActivityLaunched();
Log.d("RHINO", "afterActivityLaunched");
}
@Override
protected void afterActivityFinished() {
super.afterActivityFinished();
Log.d("RHINO", "afterActivityFinished");
}
};
@Before
public void setUp() throws Exception {
Log.d("RHINO", "setUp");
delay(1000);
}
@After
public void tearDown() throws Exception {
delay(10000);
Log.d("RHINO", "tearDown");
}
@Test
public void emptyTest() {
Log.d("RHINO", "emptyTest");
}
@Test
public void testProjectName() {
Log.d("RHINO", "testProjectName");
testProjectName("四川100变电项目");
testProjectName("四川100KV变电项目");
testProjectName("四川100Kv变电项目");
testProjectName("100kv四川变电项目");
testProjectName("四川变电项目100kV");
testProjectName("四川V变电项目");
testProjectName("四川100V变电项目");
testProjectName("100v四川变电项目");
}
private void testProjectName(String name) {
delay(1000);
onView(withId(R.id.edit)).perform(replaceText(name), closeSoftKeyboard());
onView(withText("保存")).perform(click());
}
private void delay(long millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}