Commit 20f35939 authored by Sarabjeet Singh's avatar Sarabjeet Singh

Added Espresso Tests and other configuration settings for TippyTipper

parent 55eb82e3
......@@ -5,22 +5,26 @@
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="5">
<list size="7">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
<item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<list size="6">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
</list>
</value>
</option>
......
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -6,11 +6,12 @@ android {
defaultConfig {
applicationId "net.mandaria.tippytipper"
minSdkVersion 3
minSdkVersion 14
targetSdkVersion 4
testApplicationId "net.mandaria.tippytipper.test"
testInstrumentationRunner "net.mandaria.tippytipper.EmmaInstrument.EmmaInstrumentation"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//testHandlingProfiling true
}
......@@ -25,4 +26,9 @@ android {
dependencies {
implementation files('libs/FlurryAgent.jar')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2', {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestCompile 'com.android.support.test:runner:1.0.2'
}
package net.mandaria.tippytipper.activities;
import android.support.test.espresso.ViewInteraction;
import android.support.test.filters.LargeTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import net.mandaria.tippytipper.R;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.hamcrest.core.IsInstanceOf;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.is;
@LargeTest
@RunWith(AndroidJUnit4.class)
public class TrinkgeldBerechnungTest {
@Rule
public ActivityTestRule<TippyTipper> mActivityTestRule = new ActivityTestRule(TippyTipper.class);
@Test
public void trinkgeldBerechnung() {
ViewInteraction button = onView(
allOf(withId(R.id.btn_five), withText("5"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
1),
1),
isDisplayed()));
button.perform(click());
// A sleep statement is added to match app's execution delay.
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction button2 = onView(
allOf(withId(R.id.btn_zero), withText("0"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
3),
1),
isDisplayed()));
button2.perform(click());
// A sleep statement is added to match app's execution delay.
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction button3 = onView(
allOf(withId(R.id.btn_zero), withText("0"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
3),
1),
isDisplayed()));
button3.perform(click());
// A sleep statement is added to match app's execution delay.
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction button4 = onView(
allOf(withId(R.id.btn_zero), withText("0"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
3),
1),
isDisplayed()));
button4.perform(click());
// A sleep statement is added to match app's execution delay.
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction button5 = onView(
allOf(withId(R.id.btn_zero), withText("0"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
3),
1),
isDisplayed()));
button5.perform(click());
// A sleep statement is added to match app's execution delay.
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction button6 = onView(
allOf(withId(R.id.btn_ok), withText("OK"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
3),
2),
isDisplayed()));
button6.perform(click());
// A sleep statement is added to match app's execution delay.
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction button7 = onView(
allOf(withId(R.id.btn_TipAmount3), withText("20%"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.TableLayout")),
0),
2),
isDisplayed()));
button7.perform(click());
// A sleep statement is added to match app's execution delay.
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction textView = onView(
allOf(withId(R.id.lbl_bill_amount), withText("$500.00"),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.TableRow.class),
0),
1),
isDisplayed()));
textView.check(matches(withText("$500.00")));
ViewInteraction textView2 = onView(
allOf(withId(R.id.lbl_tip_amount), withText("$100.00"),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.TableRow.class),
0),
1),
isDisplayed()));
textView2.check(matches(withText("$100.00")));
ViewInteraction textView3 = onView(
allOf(withId(R.id.lbl_total_amount), withText("$600.00"),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.TableRow.class),
0),
1),
isDisplayed()));
textView3.check(matches(withText("$600.00")));
}
private static Matcher<View> childAtPosition(
final Matcher<View> parentMatcher, final int position) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent)
&& view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}
}
......@@ -31,7 +31,7 @@
</receiver>
<activity android:label="EmmaInstrumentationActivity" android:name="net.mandaria.tippytipper.EmmaInstrument.InstrumentedActivity"/>
</application>
<instrumentation android:handleProfiling="true" android:label="EmmaInstrumentation" android:name="net.mandaria.tippytipper.EmmaInstrument.EmmaInstrumentation" android:targetPackage="net.mandaria.tippytipper"/>
<instrumentation android:handleProfiling="true" android:label="EmmaInstrumentation" android:name="android.support.test.runner.AndroidJUnitRunner" android:targetPackage="net.mandaria.tippytipper"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
......
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven {
url 'https://dl.google.com/dl/android/maven2'
}
jcenter()
google()
}
......
......@@ -4,3 +4,4 @@ distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-all.zip
android.enableAapt2=false
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment