Skip to content

Commit 6c9c98e

Browse files
ravidsrkRavindra Kumar
authored andcommitted
Updated dependencies
1 parent c013b7e commit 6c9c98e

File tree

7 files changed

+53
-271
lines changed

7 files changed

+53
-271
lines changed

README.md

Lines changed: 0 additions & 224 deletions
Original file line numberDiff line numberDiff line change
@@ -698,230 +698,6 @@ public class MainActivityRobotiumTest {
698698

699699
[MainActivityRobotiumTestRule.java](https://github.com/ravidsrk/android-testing-guide/blob/master/SampleApp/app/src/androidTest/java/in/ravidsrk/sample/MainActivityRobotiumTestRule.java)
700700

701-
```java
702-
@Beta
703-
public class MainActivityRobotiumTestRule<T extends Activity> extends UiThreadTestRule {
704-
705-
private static final String TAG = "InstrumentationRule";
706-
private final Class<T> mActivityClass;
707-
708-
public Instrumentation getInstrumentation() {
709-
return mInstrumentation;
710-
}
711-
712-
private Instrumentation mInstrumentation;
713-
private boolean mInitialTouchMode = false;
714-
private boolean mLaunchActivity = false;
715-
private T mActivity;
716-
717-
/**
718-
* Similar to {@link #MainActivityRobotiumTestRule(Class, boolean, boolean)} but with "touch mode" disabled.
719-
*
720-
* @param activityClass The activity under test. This must be a class in the instrumentation
721-
* targetPackage specified in the AndroidManifest.xml
722-
* @see MainActivityRobotiumTestRule#MainActivityRobotiumTestRule(Class, boolean, boolean)
723-
*/
724-
public MainActivityRobotiumTestRule(Class<T> activityClass) {
725-
this(activityClass, false);
726-
}
727-
728-
/**
729-
* Similar to {@link #MainActivityRobotiumTestRule(Class, boolean, boolean)} but defaults to launch the
730-
* activity under test once per
731-
* <a href="http://junit.org/javadoc/latest/org/junit/Test.html"><code>Test</code></a> method.
732-
* It is launched before the first
733-
* <a href="http://junit.sourceforge.net/javadoc/org/junit/Before.html"><code>Before</code></a>
734-
* method, and terminated after the last
735-
* <a href="http://junit.sourceforge.net/javadoc/org/junit/After.html"><code>After</code></a>
736-
* method.
737-
*
738-
* @param activityClass The activity under test. This must be a class in the instrumentation
739-
* targetPackage specified in the AndroidManifest.xml
740-
* @param initialTouchMode true if the Activity should be placed into "touch mode" when started
741-
* @see MainActivityRobotiumTestRule#MainActivityRobotiumTestRule(Class, boolean, boolean)
742-
*/
743-
public MainActivityRobotiumTestRule(Class<T> activityClass, boolean initialTouchMode) {
744-
this(activityClass, initialTouchMode, true);
745-
}
746-
747-
/**
748-
* Creates an {@link MainActivityRobotiumTestRule} for the Activity under test.
749-
*
750-
* @param activityClass The activity under test. This must be a class in the instrumentation
751-
* targetPackage specified in the AndroidManifest.xml
752-
* @param initialTouchMode true if the Activity should be placed into "touch mode" when started
753-
* @param launchActivity true if the Activity should be launched once per
754-
* <a href="http://junit.org/javadoc/latest/org/junit/Test.html">
755-
* <code>Test</code></a> method. It will be launched before the first
756-
* <a href="http://junit.sourceforge.net/javadoc/org/junit/Before.html">
757-
* <code>Before</code></a> method, and terminated after the last
758-
* <a href="http://junit.sourceforge.net/javadoc/org/junit/After.html">
759-
* <code>After</code></a> method.
760-
*/
761-
public MainActivityRobotiumTestRule(Class<T> activityClass, boolean initialTouchMode,
762-
boolean launchActivity) {
763-
mActivityClass = activityClass;
764-
mInitialTouchMode = initialTouchMode;
765-
mLaunchActivity = launchActivity;
766-
mInstrumentation = InstrumentationRegistry.getInstrumentation();
767-
}
768-
769-
/**
770-
* Override this method to set up Intent as if supplied to
771-
* {@link android.content.Context#startActivity}.
772-
* <p>
773-
* The default Intent (if this method returns null or is not overwritten) is:
774-
* action = {@link Intent#ACTION_MAIN}
775-
* flags = {@link Intent#FLAG_ACTIVITY_NEW_TASK}
776-
* All other intent fields are null or empty.
777-
*
778-
* @return The Intent as if supplied to {@link android.content.Context#startActivity}.
779-
*/
780-
protected Intent getActivityIntent() {
781-
return new Intent(Intent.ACTION_MAIN);
782-
}
783-
784-
/**
785-
* Override this method to execute any code that should run before your {@link Activity} is
786-
* created and launched.
787-
* This method is called before each test method, including any method annotated with
788-
* <a href="http://junit.sourceforge.net/javadoc/org/junit/Before.html"><code>Before</code></a>.
789-
*/
790-
protected void beforeActivityLaunched() {
791-
// empty by default
792-
}
793-
794-
/**
795-
* Override this method to execute any code that should run after your {@link Activity} is
796-
* launched, but before any test code is run including any method annotated with
797-
* <a href="http://junit.sourceforge.net/javadoc/org/junit/Before.html"><code>Before</code></a>.
798-
* <p>
799-
* Prefer
800-
* <a href="http://junit.sourceforge.net/javadoc/org/junit/Before.html"><code>Before</code></a>
801-
* over this method. This method should usually not be overwritten directly in tests and only be
802-
* used by subclasses of MainActivityRobotiumTestRule to get notified when the activity is created and
803-
* visible but test runs.
804-
*/
805-
protected void afterActivityLaunched() {
806-
// empty by default
807-
}
808-
809-
/**
810-
* Override this method to execute any code that should run after your {@link Activity} is
811-
* finished.
812-
* This method is called after each test method, including any method annotated with
813-
* <a href="http://junit.sourceforge.net/javadoc/org/junit/After.html"><code>After</code></a>.
814-
*/
815-
protected void afterActivityFinished() {
816-
// empty by default
817-
}
818-
819-
/**
820-
* @return The activity under test.
821-
*/
822-
public T getActivity() {
823-
if (mActivity == null) {
824-
Log.w(TAG, "Activity wasn't created yet");
825-
}
826-
return mActivity;
827-
}
828-
829-
@Override
830-
public Statement apply(final Statement base, Description description) {
831-
return new ActivityStatement(super.apply(base, description));
832-
}
833-
834-
/**
835-
* Launches the Activity under test.
836-
* <p>
837-
* Don't call this method directly, unless you explicitly requested not to launch the Activity
838-
* manually using the launchActivity flag in
839-
* {@link MainActivityRobotiumTestRule#MainActivityRobotiumTestRule(Class, boolean, boolean)}.
840-
* <p>
841-
* Usage:
842-
* <pre>
843-
* &#064;Test
844-
* public void customIntentToStartActivity() {
845-
* Intent intent = new Intent(Intent.ACTION_PICK);
846-
* mActivity = mActivityRule.launchActivity(intent);
847-
* }
848-
* </pre>
849-
* @param startIntent The Intent that will be used to start the Activity under test. If
850-
* {@code startIntent} is null, the Intent returned by
851-
* {@link MainActivityRobotiumTestRule#getActivityIntent()} is used.
852-
* @return the Activity launched by this rule.
853-
* @see MainActivityRobotiumTestRule#getActivityIntent()
854-
*/
855-
public T launchActivity(@Nullable Intent startIntent) {
856-
// set initial touch mode
857-
mInstrumentation.setInTouchMode(mInitialTouchMode);
858-
859-
final String targetPackage = mInstrumentation.getTargetContext().getPackageName();
860-
// inject custom intent, if provided
861-
if (null == startIntent) {
862-
startIntent = getActivityIntent();
863-
if (null == startIntent) {
864-
Log.w(TAG, "getActivityIntent() returned null using default: " +
865-
"Intent(Intent.ACTION_MAIN)");
866-
startIntent = new Intent(Intent.ACTION_MAIN);
867-
}
868-
}
869-
startIntent.setClassName(targetPackage, mActivityClass.getName());
870-
startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
871-
Log.d(TAG, String.format("Launching activity %s",
872-
mActivityClass.getName()));
873-
874-
beforeActivityLaunched();
875-
// The following cast is correct because the activity we're creating is of the same type as
876-
// the one passed in
877-
mActivity = mActivityClass.cast(mInstrumentation.startActivitySync(startIntent));
878-
879-
mInstrumentation.waitForIdleSync();
880-
881-
afterActivityLaunched();
882-
return mActivity;
883-
}
884-
885-
// Visible for testing
886-
void setInstrumentation(Instrumentation instrumentation) {
887-
mInstrumentation = checkNotNull(instrumentation, "instrumentation cannot be null!");
888-
}
889-
890-
void finishActivity() {
891-
if (mActivity != null) {
892-
mActivity.finish();
893-
mActivity = null;
894-
}
895-
}
896-
897-
/**
898-
* <a href="http://junit.org/apidocs/org/junit/runners/model/Statement.html">
899-
* <code>Statement</code></a> that finishes the activity after the test was executed
900-
*/
901-
private class ActivityStatement extends Statement {
902-
903-
private final Statement mBase;
904-
905-
public ActivityStatement(Statement base) {
906-
mBase = base;
907-
}
908-
909-
@Override
910-
public void evaluate() throws Throwable {
911-
try {
912-
if (mLaunchActivity) {
913-
mActivity = launchActivity(getActivityIntent());
914-
}
915-
mBase.evaluate();
916-
} finally {
917-
finishActivity();
918-
afterActivityFinished();
919-
}
920-
}
921-
}
922-
923-
}
924-
```
925701
### UI testing and UI Automator
926702

927703
[MainActivityTest](https://github.com/ravidsrk/android-testing-guide/blob/master/SampleApp/app/src/androidTest/java/in/ravidsrk/sample/MainActivityTest.java#L101)

SampleApp/app/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 24
5-
buildToolsVersion "24.0.2"
4+
compileSdkVersion 25
5+
buildToolsVersion "25.0.2"
66
defaultConfig {
77
applicationId "in.ravidsrk.sample"
88
minSdkVersion 18
9-
targetSdkVersion 24
9+
targetSdkVersion 25
1010
versionCode 1
1111
versionName "1.0"
1212
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -20,8 +20,8 @@ android {
2020
}
2121

2222
dependencies {
23-
compile 'com.android.support:appcompat-v7:24.2.0'
24-
compile 'com.android.support:design:24.2.0'
23+
compile 'com.android.support:appcompat-v7:25.1.0'
24+
compile 'com.android.support:design:25.1.0'
2525

2626
testCompile 'junit:junit:4.12'
2727
testCompile "org.robolectric:robolectric:3.1"
@@ -35,7 +35,7 @@ dependencies {
3535
androidTestCompile "org.mockito:mockito-core:1.9.5"
3636
androidTestCompile "com.google.dexmaker:dexmaker:1.2"
3737
androidTestCompile "com.google.dexmaker:dexmaker-mockito:1.2"
38-
androidTestCompile 'com.android.support:support-annotations:24.2.0'
38+
androidTestCompile 'com.android.support:support-annotations:25.1.0'
3939
androidTestCompile 'com.android.support.test:runner:0.5'
4040
androidTestCompile 'com.android.support.test:rules:0.5'
4141
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'

SampleApp/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.2.0-rc2'
8+
classpath 'com.android.tools.build:gradle:2.2.3'
99

1010
// NOTE: Do not place your application dependencies here; they belong
1111
// in the individual module build.gradle files
572 Bytes
Binary file not shown.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon Dec 28 10:00:20 PST 2015
1+
#Sun Jan 08 20:48:46 IST 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

SampleApp/gradlew

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
1-
#!/usr/bin/env bash
1+
#!/usr/bin/env sh
22

33
##############################################################################
44
##
55
## Gradle start up script for UN*X
66
##
77
##############################################################################
88

9-
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10-
DEFAULT_JVM_OPTS=""
9+
# Attempt to set APP_HOME
10+
# Resolve links: $0 may be a link
11+
PRG="$0"
12+
# Need this for relative symlinks.
13+
while [ -h "$PRG" ] ; do
14+
ls=`ls -ld "$PRG"`
15+
link=`expr "$ls" : '.*-> \(.*\)$'`
16+
if expr "$link" : '/.*' > /dev/null; then
17+
PRG="$link"
18+
else
19+
PRG=`dirname "$PRG"`"/$link"
20+
fi
21+
done
22+
SAVED="`pwd`"
23+
cd "`dirname \"$PRG\"`/" >/dev/null
24+
APP_HOME="`pwd -P`"
25+
cd "$SAVED" >/dev/null
1126

1227
APP_NAME="Gradle"
1328
APP_BASE_NAME=`basename "$0"`
1429

30+
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31+
DEFAULT_JVM_OPTS=""
32+
1533
# Use the maximum available, or set MAX_FD != -1 to use that value.
1634
MAX_FD="maximum"
1735

@@ -30,6 +48,7 @@ die ( ) {
3048
cygwin=false
3149
msys=false
3250
darwin=false
51+
nonstop=false
3352
case "`uname`" in
3453
CYGWIN* )
3554
cygwin=true
@@ -40,26 +59,11 @@ case "`uname`" in
4059
MINGW* )
4160
msys=true
4261
;;
62+
NONSTOP* )
63+
nonstop=true
64+
;;
4365
esac
4466

45-
# Attempt to set APP_HOME
46-
# Resolve links: $0 may be a link
47-
PRG="$0"
48-
# Need this for relative symlinks.
49-
while [ -h "$PRG" ] ; do
50-
ls=`ls -ld "$PRG"`
51-
link=`expr "$ls" : '.*-> \(.*\)$'`
52-
if expr "$link" : '/.*' > /dev/null; then
53-
PRG="$link"
54-
else
55-
PRG=`dirname "$PRG"`"/$link"
56-
fi
57-
done
58-
SAVED="`pwd`"
59-
cd "`dirname \"$PRG\"`/" >/dev/null
60-
APP_HOME="`pwd -P`"
61-
cd "$SAVED" >/dev/null
62-
6367
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
6468

6569
# Determine the Java command to use to start the JVM.
@@ -85,7 +89,7 @@ location of your Java installation."
8589
fi
8690

8791
# Increase the maximum file descriptors if we can.
88-
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
92+
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
8993
MAX_FD_LIMIT=`ulimit -H -n`
9094
if [ $? -eq 0 ] ; then
9195
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
@@ -150,11 +154,19 @@ if $cygwin ; then
150154
esac
151155
fi
152156

153-
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154-
function splitJvmOpts() {
155-
JVM_OPTS=("$@")
157+
# Escape application args
158+
save ( ) {
159+
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160+
echo " "
156161
}
157-
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158-
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
162+
APP_ARGS=$(save "$@")
163+
164+
# Collect all arguments for the java command, following the shell quoting and substitution rules
165+
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166+
167+
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168+
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169+
cd "$(dirname "$0")"
170+
fi
159171

160-
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
172+
exec "$JAVACMD" "$@"

0 commit comments

Comments
 (0)