[ADD] Location Tests + ID at every XML file

This commit is contained in:
Robin Koedood
2021-01-05 10:58:33 +01:00
parent bcd9eb6378
commit d3cab8c70d
14 changed files with 57 additions and 1 deletions

View File

@@ -56,4 +56,7 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
testImplementation 'org.mockito:mockito-core:2.7.22' testImplementation 'org.mockito:mockito-core:2.7.22'
androidTestImplementation 'com.21buttons:fragment-test-rule:2.0.1'
androidTestImplementation 'androidx.test:rules:1.3.0-beta01'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0-alpha02'
} }

View File

@@ -0,0 +1,41 @@
package com.a1.nextlocation;
import androidx.test.espresso.contrib.RecyclerViewActions;
import androidx.test.rule.ActivityTestRule;
import com.a1.nextlocation.fragments.LocationFragment;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import javax.inject.Inject;
import static androidx.test.espresso.Espresso.*;
import static androidx.test.espresso.action.ViewActions.*;
import static androidx.test.espresso.assertion.ViewAssertions.*;
import static androidx.test.espresso.matcher.ViewMatchers.*;
public class LocationFragmentTest {
@Rule
public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class);
@Test
public void clickBackButton() throws Exception{
mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new LocationFragment()).commit();
onView(withId(R.id.locationBackButton)).perform(click());
onView(withId(R.id.homeFragment)).check(matches(isDisplayed()));
}
@Test
public void clickDetailButton() throws Exception{
mActivityTestRule.getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.mainActivity, new LocationFragment()).commit();
onView(withId(R.id.locationRecyclerView)).perform(RecyclerViewActions.actionOnItemAtPosition(1, click()));
onView(withId(R.id.locationDetailFragment)).check(matches(isDisplayed()));
}
}

View File

@@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/mainActivity"
tools:context=".MainActivity"> tools:context=".MainActivity">
<FrameLayout <FrameLayout

View File

@@ -2,6 +2,7 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:id="@+id/couponItem"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout

View File

@@ -5,6 +5,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/primaryColour" android:background="@color/primaryColour"
android:id="@+id/couponFragment"
tools:context=".fragments.LocationFragment"> tools:context=".fragments.LocationFragment">
<TextView <TextView

View File

@@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/homeFragment"
tools:context=".fragments.HomeFragment"> tools:context=".fragments.HomeFragment">

View File

@@ -5,6 +5,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/primaryColour" android:background="@color/primaryColour"
android:id="@+id/locationFragment"
tools:context=".fragments.LocationFragment"> tools:context=".fragments.LocationFragment">
<TextView <TextView
@@ -35,5 +36,5 @@
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/routeBackButton" /> app:layout_constraintTop_toBottomOf="@+id/locationBackButton" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -5,6 +5,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/primaryColour" android:background="@color/primaryColour"
android:id="@+id/locationDetailFragment"
tools:context=".fragments.LocationDetailFragment"> tools:context=".fragments.LocationDetailFragment">
<TextView <TextView

View File

@@ -5,6 +5,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/primaryColour" android:background="@color/primaryColour"
android:id="@+id/routeFragment"
tools:context=".fragments.RouteFragment"> tools:context=".fragments.RouteFragment">
<ImageButton <ImageButton

View File

@@ -5,6 +5,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/primaryColour" android:background="@color/primaryColour"
android:id="@+id/routeDetailFragment"
tools:context=".fragments.RouteDetailFragment"> tools:context=".fragments.RouteDetailFragment">
<ImageButton <ImageButton

View File

@@ -5,6 +5,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/primaryColour" android:background="@color/primaryColour"
android:id="@+id/settingFragment"
tools:context=".fragments.SettingsFragment"> tools:context=".fragments.SettingsFragment">
<androidx.appcompat.widget.AppCompatImageButton <androidx.appcompat.widget.AppCompatImageButton

View File

@@ -5,6 +5,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/primaryColour" android:background="@color/primaryColour"
android:id="@+id/statisticsFragment"
tools:context=".fragments.StatisticFragment"> tools:context=".fragments.StatisticFragment">
<TextView <TextView

View File

@@ -4,6 +4,7 @@
android:layout_height="50dp" android:layout_height="50dp"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/secondaryColour" android:background="@color/secondaryColour"
android:id="@+id/locationItem"
android:layout_margin="20dp"> android:layout_margin="20dp">
<ImageView <ImageView

View File

@@ -4,6 +4,7 @@
android:layout_height="50dp" android:layout_height="50dp"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/secondaryColour" android:background="@color/secondaryColour"
android:id="@+id/routeItem"
android:layout_margin="20dp"> android:layout_margin="20dp">
<ImageView <ImageView