-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for BOINCActivity and its fragments.
- Loading branch information
1 parent
57d71cc
commit cc6e86a
Showing
3 changed files
with
166 additions
and
20 deletions.
There are no files selected for viewing
144 changes: 144 additions & 0 deletions
144
android/BOINC/app/src/androidTest/java/edu/berkeley/boinc/BOINCActivityTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package edu.berkeley.boinc | ||
|
||
import androidx.test.espresso.Espresso.onView | ||
import androidx.test.espresso.action.ViewActions.click | ||
import androidx.test.espresso.assertion.ViewAssertions.matches | ||
import androidx.test.espresso.matcher.ViewMatchers.* | ||
import androidx.test.ext.junit.rules.ActivityScenarioRule | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.filters.LargeTest | ||
import org.hamcrest.Matchers.allOf | ||
import org.hamcrest.core.IsInstanceOf | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
// Disable BOINC notifications (or just the main channel on Oreo and higher) before running this test, as | ||
// the client notification can cover the hamburger button during test execution and cause the test to fail. | ||
@LargeTest | ||
@RunWith(AndroidJUnit4::class) | ||
class BOINCActivityTest { | ||
@Rule | ||
@JvmField | ||
var mActivityScenarioRule = ActivityScenarioRule(BOINCActivity::class.java) | ||
|
||
@Test | ||
fun boincActivityTest() { | ||
val textView = onView( | ||
allOf(withText(R.string.tab_tasks), | ||
withParent(allOf(withId(R.id.action_bar), | ||
withParent(withId(R.id.action_bar_container)))), | ||
isDisplayed())) | ||
textView.check(matches(withText(R.string.tab_tasks))) | ||
|
||
val appCompatImageButton = onView( | ||
allOf(withContentDescription("BOINC"), | ||
childAtPosition( | ||
allOf(withId(R.id.action_bar), | ||
childAtPosition( | ||
withId(R.id.action_bar_container), | ||
0)), | ||
1), | ||
isDisplayed())) | ||
appCompatImageButton.perform(click()) | ||
|
||
val viewInteraction = onView(allOf(withText(R.string.tab_notices), isDisplayed())) | ||
viewInteraction.perform(click()) | ||
|
||
val textView2 = onView( | ||
allOf(withText(R.string.tab_notices), | ||
withParent(allOf(withId(R.id.action_bar), | ||
withParent(withId(R.id.action_bar_container)))), | ||
isDisplayed())) | ||
textView2.check(matches(withText(R.string.tab_notices))) | ||
|
||
appCompatImageButton.perform(click()) | ||
|
||
val viewInteraction2 = onView(allOf(withText(R.string.tab_projects), isDisplayed())) | ||
viewInteraction2.perform(click()) | ||
|
||
val textView3 = onView( | ||
allOf(withText(R.string.tab_projects), | ||
withParent(allOf(withId(R.id.action_bar), | ||
withParent(withId(R.id.action_bar_container)))), | ||
isDisplayed())) | ||
textView3.check(matches(withText(R.string.tab_projects))) | ||
|
||
appCompatImageButton.perform(click()) | ||
|
||
val viewInteraction3 = onView(allOf(withText(R.string.tab_preferences), isDisplayed())) | ||
viewInteraction3.perform(click()) | ||
|
||
val textView4 = onView( | ||
allOf(withText(R.string.tab_preferences), | ||
withParent(allOf(withId(R.id.action_bar), | ||
withParent(withId(R.id.action_bar_container)))), | ||
isDisplayed())) | ||
textView4.check(matches(withText(R.string.tab_preferences))) | ||
|
||
appCompatImageButton.perform(click()) | ||
|
||
val viewInteraction4 = onView(allOf(withText(R.string.menu_about), isDisplayed())) | ||
viewInteraction4.perform(click()) | ||
|
||
val textView5 = onView( | ||
allOf(withId(R.id.title), withText(R.string.menu_about), | ||
withParent(withParent(withId(android.R.id.content))), | ||
isDisplayed())) | ||
textView5.check(matches(withText(R.string.menu_about))) | ||
|
||
val appCompatButton = onView( | ||
allOf(withId(R.id.returnB), withText(R.string.about_button), | ||
childAtPosition( | ||
childAtPosition( | ||
withId(android.R.id.content), | ||
0), | ||
6), | ||
isDisplayed())) | ||
appCompatButton.perform(click()) | ||
|
||
appCompatImageButton.perform(click()) | ||
|
||
val viewInteraction5 = onView(allOf(withText(R.string.menu_eventlog), isDisplayed())) | ||
viewInteraction5.perform(click()) | ||
|
||
val textView6 = onView( | ||
allOf(withText(R.string.menu_eventlog), | ||
withParent(allOf(withId(R.id.action_bar), | ||
withParent(withId(R.id.action_bar_container)))), | ||
isDisplayed())) | ||
textView6.check(matches(withText(R.string.menu_eventlog))) | ||
|
||
val textView7 = onView( | ||
allOf(withText(R.string.eventlog_client_header), | ||
withParent(allOf(withContentDescription(R.string.eventlog_client_header), | ||
withParent(IsInstanceOf.instanceOf(android.widget.LinearLayout::class.java)))), | ||
isDisplayed())) | ||
textView7.check(matches(withText(R.string.eventlog_client_header))) | ||
|
||
val textView8 = onView( | ||
allOf(withText(R.string.eventlog_gui_header), | ||
withParent(allOf(withContentDescription(R.string.eventlog_gui_header), | ||
withParent(IsInstanceOf.instanceOf(android.widget.LinearLayout::class.java)))), | ||
isDisplayed())) | ||
textView8.check(matches(withText(R.string.eventlog_gui_header))) | ||
|
||
val appCompatImageButton2 = onView( | ||
allOf(withContentDescription("Navigate up"), | ||
childAtPosition( | ||
allOf(withId(R.id.action_bar), | ||
childAtPosition( | ||
withId(R.id.action_bar_container), | ||
0)), | ||
1), | ||
isDisplayed())) | ||
appCompatImageButton2.perform(click()) | ||
|
||
val textView9 = onView( | ||
allOf(withText(R.string.tab_tasks), | ||
withParent(allOf(withId(R.id.action_bar), | ||
withParent(withId(R.id.action_bar_container)))), | ||
isDisplayed())) | ||
textView9.check(matches(withText(R.string.tab_tasks))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
android/BOINC/app/src/androidTest/java/edu/berkeley/boinc/TestUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package edu.berkeley.boinc | ||
|
||
import android.view.View | ||
import android.view.ViewGroup | ||
import org.hamcrest.Description | ||
import org.hamcrest.Matcher | ||
import org.hamcrest.TypeSafeMatcher | ||
|
||
fun childAtPosition(parentMatcher: Matcher<View>, position: Int): Matcher<View> { | ||
return object : TypeSafeMatcher<View>() { | ||
override fun describeTo(description: Description) { | ||
description.appendText("Child at position $position in parent ") | ||
parentMatcher.describeTo(description) | ||
} | ||
|
||
public override fun matchesSafely(view: View): Boolean { | ||
val parent = view.parent | ||
return parent is ViewGroup && parentMatcher.matches(parent) | ||
&& view == parent.getChildAt(position) | ||
} | ||
} | ||
} |