Skip to content

Commit 67801b6

Browse files
Add test for BOINCActivity.
1 parent 7e27d97 commit 67801b6

File tree

3 files changed

+210
-20
lines changed

3 files changed

+210
-20
lines changed
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
* This file is part of BOINC.
3+
* http://boinc.berkeley.edu
4+
* Copyright (C) 2020 University of California
5+
*
6+
* BOINC is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU Lesser General Public License
8+
* as published by the Free Software Foundation,
9+
* either version 3 of the License, or (at your option) any later version.
10+
*
11+
* BOINC is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14+
* See the GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with BOINC. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
package edu.berkeley.boinc
20+
21+
import androidx.test.espresso.Espresso.onView
22+
import androidx.test.espresso.action.ViewActions.click
23+
import androidx.test.espresso.assertion.ViewAssertions.matches
24+
import androidx.test.espresso.matcher.ViewMatchers.*
25+
import androidx.test.ext.junit.rules.ActivityScenarioRule
26+
import androidx.test.ext.junit.runners.AndroidJUnit4
27+
import androidx.test.filters.LargeTest
28+
import org.hamcrest.Matchers.allOf
29+
import org.junit.Rule
30+
import org.junit.Test
31+
import org.junit.runner.RunWith
32+
33+
@LargeTest
34+
@RunWith(AndroidJUnit4::class)
35+
class BOINCActivityTest {
36+
@Rule
37+
@JvmField
38+
var mActivityScenarioRule = ActivityScenarioRule(BOINCActivity::class.java)
39+
40+
@Test
41+
fun boincActivityTest() {
42+
val appCompatImageButton = onView(
43+
allOf(withContentDescription("Navigate up"),
44+
childAtPosition(
45+
allOf(withId(R.id.action_bar),
46+
childAtPosition(
47+
withId(R.id.action_bar_container),
48+
0)),
49+
1),
50+
isDisplayed()))
51+
appCompatImageButton.perform(click())
52+
53+
val textView = onView(
54+
allOf(withId(R.id.title), withText("Tasks"),
55+
childAtPosition(
56+
allOf(withId(R.id.listitem),
57+
childAtPosition(
58+
withId(R.id.list_slidermenu),
59+
0)),
60+
1),
61+
isDisplayed()))
62+
textView.check(matches(withText("Tasks")))
63+
64+
val textView2 = onView(
65+
allOf(withId(R.id.title), withText("Notices"),
66+
childAtPosition(
67+
allOf(withId(R.id.listitem),
68+
childAtPosition(
69+
withId(R.id.list_slidermenu),
70+
1)),
71+
1),
72+
isDisplayed()))
73+
textView2.check(matches(withText("Notices")))
74+
75+
val textView3 = onView(
76+
allOf(withId(R.id.title), withText("Projects"),
77+
childAtPosition(
78+
allOf(withId(R.id.listitem),
79+
childAtPosition(
80+
withId(R.id.list_slidermenu),
81+
2)),
82+
1),
83+
isDisplayed()))
84+
textView3.check(matches(withText("Projects")))
85+
86+
val textView4 = onView(
87+
allOf(withId(R.id.title), withText("Add project"),
88+
childAtPosition(
89+
allOf(withId(R.id.listitem),
90+
childAtPosition(
91+
withId(R.id.list_slidermenu),
92+
3)),
93+
1),
94+
isDisplayed()))
95+
textView4.check(matches(withText("Add project")))
96+
97+
val textView5 = onView(
98+
allOf(withId(R.id.title), withText("Preferences"),
99+
childAtPosition(
100+
allOf(withId(R.id.listitem),
101+
childAtPosition(
102+
withId(R.id.list_slidermenu),
103+
4)),
104+
1),
105+
isDisplayed()))
106+
textView5.check(matches(withText("Preferences")))
107+
108+
val textView6 = onView(
109+
allOf(withId(R.id.title), withText("Help"),
110+
childAtPosition(
111+
allOf(withId(R.id.listitem),
112+
childAtPosition(
113+
withId(R.id.list_slidermenu),
114+
5)),
115+
1),
116+
isDisplayed()))
117+
textView6.check(matches(withText("Help")))
118+
119+
val textView7 = onView(
120+
allOf(withId(R.id.title), withText("Report Issue"),
121+
childAtPosition(
122+
allOf(withId(R.id.listitem),
123+
childAtPosition(
124+
withId(R.id.list_slidermenu),
125+
6)),
126+
1),
127+
isDisplayed()))
128+
textView7.check(matches(withText("Report Issue")))
129+
130+
val textView8 = onView(
131+
allOf(withId(R.id.title), withText("About"),
132+
childAtPosition(
133+
allOf(withId(R.id.listitem),
134+
childAtPosition(
135+
withId(R.id.list_slidermenu),
136+
7)),
137+
1),
138+
isDisplayed()))
139+
textView8.check(matches(withText("About")))
140+
141+
val textView9 = onView(
142+
allOf(withId(R.id.title), withText("Event Log"),
143+
childAtPosition(
144+
allOf(withId(R.id.listitem),
145+
childAtPosition(
146+
withId(R.id.list_slidermenu),
147+
8)),
148+
1),
149+
isDisplayed()))
150+
textView9.check(matches(withText("Event Log")))
151+
}
152+
}

android/BOINC/app/src/androidTest/java/edu/berkeley/boinc/SplashActivityToEventLogTest.kt

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
1+
/*
2+
* This file is part of BOINC.
3+
* http://boinc.berkeley.edu
4+
* Copyright (C) 2020 University of California
5+
*
6+
* BOINC is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU Lesser General Public License
8+
* as published by the Free Software Foundation,
9+
* either version 3 of the License, or (at your option) any later version.
10+
*
11+
* BOINC is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14+
* See the GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with BOINC. If not, see <http://www.gnu.org/licenses/>.
18+
*/
119
package edu.berkeley.boinc
220

3-
import android.view.View
4-
import android.view.ViewGroup
521
import androidx.test.espresso.Espresso.onView
622
import androidx.test.espresso.action.ViewActions.longClick
723
import androidx.test.espresso.assertion.ViewAssertions.matches
824
import androidx.test.espresso.matcher.ViewMatchers.*
925
import androidx.test.ext.junit.rules.ActivityScenarioRule
1026
import androidx.test.ext.junit.runners.AndroidJUnit4
1127
import androidx.test.filters.LargeTest
12-
import org.hamcrest.Description
13-
import org.hamcrest.Matcher
1428
import org.hamcrest.Matchers.allOf
15-
import org.hamcrest.TypeSafeMatcher
1629
import org.hamcrest.core.IsInstanceOf
1730
import org.junit.Rule
1831
import org.junit.Test
@@ -87,19 +100,4 @@ class SplashActivityToEventLogTest {
87100
isDisplayed()))
88101
textView5.check(matches(withText("GUI MESSAGES")))
89102
}
90-
91-
private fun childAtPosition(parentMatcher: Matcher<View>, position: Int): Matcher<View> {
92-
return object : TypeSafeMatcher<View>() {
93-
override fun describeTo(description: Description) {
94-
description.appendText("Child at position $position in parent ")
95-
parentMatcher.describeTo(description)
96-
}
97-
98-
public override fun matchesSafely(view: View): Boolean {
99-
val parent = view.parent
100-
return parent is ViewGroup && parentMatcher.matches(parent)
101-
&& view == parent.getChildAt(position)
102-
}
103-
}
104-
}
105103
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* This file is part of BOINC.
3+
* http://boinc.berkeley.edu
4+
* Copyright (C) 2020 University of California
5+
*
6+
* BOINC is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU Lesser General Public License
8+
* as published by the Free Software Foundation,
9+
* either version 3 of the License, or (at your option) any later version.
10+
*
11+
* BOINC is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14+
* See the GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with BOINC. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
package edu.berkeley.boinc
20+
21+
import android.view.View
22+
import android.view.ViewGroup
23+
import org.hamcrest.Description
24+
import org.hamcrest.Matcher
25+
import org.hamcrest.TypeSafeMatcher
26+
27+
fun childAtPosition(parentMatcher: Matcher<View>, position: Int): Matcher<View> {
28+
return object : TypeSafeMatcher<View>() {
29+
override fun describeTo(description: Description) {
30+
description.appendText("Child at position $position in parent ")
31+
parentMatcher.describeTo(description)
32+
}
33+
34+
public override fun matchesSafely(view: View): Boolean {
35+
val parent = view.parent
36+
return parent is ViewGroup && parentMatcher.matches(parent)
37+
&& view == parent.getChildAt(position)
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)