Parcourir la source

Pass test vars as instrumentation runner argumments

jabarros il y a 9 ans
Parent
commit
822a62c513

+ 15 - 10
androidTest/java/com/owncloud/android/authentication/AuthenticatorActivityTest.java

@@ -21,20 +21,18 @@ package com.owncloud.android.authentication;
 
 import android.content.Context;
 import android.content.Intent;
-import android.net.Uri;
+import android.os.Bundle;
 import android.support.test.InstrumentationRegistry;
 import android.support.test.rule.ActivityTestRule;
 import android.support.test.runner.AndroidJUnit4;
 import android.test.suitebuilder.annotation.LargeTest;
 
-import com.owncloud.android.BuildConfig;
 import static org.junit.Assert.assertTrue;
 import com.owncloud.android.R;
 
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import static org.junit.Assert.assertTrue;
 
 import java.lang.reflect.Field;
 
@@ -58,10 +56,10 @@ public class AuthenticatorActivityTest {
     public static final String EXTRA_ACTION = "ACTION";
     public static final String EXTRA_ACCOUNT = "ACCOUNT";
 
-    private static int WAIT_LOGIN = 5000;
+    private static final int WAIT_LOGIN = 5000;
 
-    private static String ERROR_MESSAGE = "Activity not finished";
-    private static String RESULT_CODE = "mResultCode";
+    private static final String ERROR_MESSAGE = "Activity not finished";
+    private static final String RESULT_CODE = "mResultCode";
 
 
     @Rule
@@ -80,7 +78,14 @@ public class AuthenticatorActivityTest {
     };
 
     @Test
-    public void check_login() throws InterruptedException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
+    public void check_login()
+        throws InterruptedException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
+        Bundle arguments = InstrumentationRegistry.getArguments();
+
+        // Get values passed
+        String testUser = arguments.getString("TEST_USER");
+        String testPassword = arguments.getString("TEST_PASSWORD");
+        String testServerURL = arguments.getString("TEST_SERVER_URL");
 
         // Check that login button is disabled
         onView(withId(R.id.buttonOK))
@@ -88,16 +93,16 @@ public class AuthenticatorActivityTest {
 
         // Type server url
         onView(withId(R.id.hostUrlInput))
-                .perform(typeText(BuildConfig.TEST_SERVER_URL), closeSoftKeyboard());
+                .perform(typeText(testServerURL), closeSoftKeyboard());
         onView(withId(R.id.account_username)).perform(click());
 
         // Type user
         onView(withId(R.id.account_username))
-                .perform(typeText(BuildConfig.TEST_USER), closeSoftKeyboard());
+                .perform(typeText(testUser), closeSoftKeyboard());
 
         // Type user pass
         onView(withId(R.id.account_password))
-                .perform(typeText(BuildConfig.TEST_PASSWORD), closeSoftKeyboard());
+                .perform(typeText(testPassword), closeSoftKeyboard());
         onView(withId(R.id.buttonOK)).perform(click());
 
         // Check that the Activity ends after clicking

+ 4 - 3
build.gradle

@@ -73,9 +73,10 @@ android {
     defaultConfig {
         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
 
-        buildConfigField "String", "TEST_USER",  "\"${TEST_USER}\""
-        buildConfigField "String", "TEST_PASSWORD",  "\"${TEST_PASSWORD}\""
-        buildConfigField "String", "TEST_SERVER_URL",  "\"${TEST_SERVER_URL}\""
+        testInstrumentationRunnerArgument "TEST_USER", "\"${TEST_USER}\""
+        testInstrumentationRunnerArgument "TEST_PASSWORD", "\"${TEST_PASSWORD}\""
+        testInstrumentationRunnerArgument "TEST_SERVER_URL", "\"${TEST_SERVER_URL}\""
+
     }
 
     // adapt structure from Eclipse to Gradle/Android Studio expectations;