瀏覽代碼

Initial text to check authentication (WIP)

jabarros 9 年之前
父節點
當前提交
db88f7f1dd
共有 2 個文件被更改,包括 103 次插入1 次删除
  1. 98 0
      androidTest/java/com/owncloud/android/authentication/AuthenticatorActivityTest.java
  2. 5 1
      build.gradle

+ 98 - 0
androidTest/java/com/owncloud/android/authentication/AuthenticatorActivityTest.java

@@ -0,0 +1,98 @@
+/**
+ *   ownCloud Android client application
+ *
+ *   Copyright (C) 2015 ownCloud Inc.
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package com.owncloud.android.authentication;
+
+import android.content.Context;
+import android.content.Intent;
+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.R;
+
+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.action.ViewActions.closeSoftKeyboard;
+import static android.support.test.espresso.action.ViewActions.typeText;
+
+import static android.support.test.espresso.matcher.ViewMatchers.isEnabled;
+import static android.support.test.espresso.matcher.ViewMatchers.withId;
+
+import static android.support.test.espresso.assertion.ViewAssertions.matches;
+import static org.hamcrest.Matchers.not;
+
+
+@RunWith(AndroidJUnit4.class)
+@LargeTest
+public class AuthenticatorActivityTest {
+
+    public static final String EXTRA_ACTION = "ACTION";
+    public static final String EXTRA_ACCOUNT = "ACCOUNT";
+
+    public static final String TEST_USER = ""; // Fill with custom values
+    public static final String TEST_PASSWORD = ""; // Fill with custom values
+    public static final String TEST_SERVER_URL = ""; // Fill with custom values
+
+
+    @Rule
+    public ActivityTestRule<AuthenticatorActivity> mActivityRule = new ActivityTestRule<AuthenticatorActivity>(
+            AuthenticatorActivity.class){
+        @Override
+        protected Intent getActivityIntent() {
+            Context targetContext = InstrumentationRegistry.getInstrumentation()
+                    .getTargetContext();
+            Intent result = new Intent(targetContext, AuthenticatorActivity.class);
+            result.putExtra(EXTRA_ACTION, "");
+            result.putExtra(EXTRA_ACCOUNT, "");
+            return result;
+        }
+    };
+
+    @Test
+    public void check_login() {
+
+        // Check that login button is disabled
+        onView(withId(R.id.buttonOK))
+                .check(matches(not(isEnabled())));
+
+        // Type server url
+        onView(withId(R.id.hostUrlInput))
+                .perform(typeText(TEST_SERVER_URL), closeSoftKeyboard());
+        onView(withId(R.id.account_username)).perform(click());
+
+        // Type user
+        onView(withId(R.id.account_username))
+                .perform(typeText(TEST_USER), closeSoftKeyboard());
+
+        // Type user pass
+        onView(withId(R.id.account_password))
+                .perform(typeText(TEST_PASSWORD), closeSoftKeyboard());
+        onView(withId(R.id.buttonOK)).perform(click());
+
+        // Check that login button is now enabled
+        onView(withId(R.id.buttonOK)).check(matches(isEnabled()));
+
+    }
+}

+ 5 - 1
build.gradle

@@ -77,9 +77,13 @@ android {
             assets.srcDirs = ['assets']
         }
 
-        // move all the local unit tests structure as a whole from src/test/* to test/*
+        // move whole local unit tests structure as a whole from src/test/* to test/*
         test.setRoot('test')
 
+        // move whole instrumented tests structure as a whole from src/androidTest/* to androidTest/*
+        androidTest.setRoot('androidTest')
+
+
         // Move the build types to build-types/<type>
         // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
         // This moves them out of them default location under src/<type>/... which would