Ver código fonte

Merge pull request #3 from subbramanil/feature/ui_testing_espresso

UI Testing using Espresso Framework
Beautus Sduduzo Gumede 7 anos atrás
pai
commit
60a36b7e74

+ 34 - 0
.circleci/config.yml

@@ -0,0 +1,34 @@
+version: 2
+jobs:
+  build:
+    working_directory: ~/code
+    docker:
+      - image: circleci/android:api-25-alpha
+    environment:
+      JVM_OPTS: -Xmx3200m
+    steps:
+      - checkout
+      - restore_cache:
+          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
+      - run:
+          name: Chmod permissions #if permission for Gradlew Dependencies fail, use this.
+          command: sudo chmod +x ./gradlew
+      - run:
+          name: Run build
+          command:  export TERM=${TERM:-dumb} && ./gradlew clean build
+      - run:
+          name: Download Dependencies
+          command: ./gradlew androidDependencies
+      - save_cache:
+          paths:
+            - ~/.gradle
+          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
+      - run:
+          name: Run Tests
+          command: ./gradlew lint test
+      - store_artifacts:
+          path: app/build/reports
+          destination: reports
+      - store_test_results:
+          path: app/build/test-results
+# See https://circleci.com/docs/2.0/deployment-integrations/ for deploy examples

+ 1 - 0
.gitignore

@@ -33,6 +33,7 @@ proguard/
 captures/
 
 # IntelliJ
+.idea/
 *.iml
 .idea/workspace.xml
 .idea/tasks.xml

+ 0 - 29
.idea/codeStyles/Project.xml

@@ -1,29 +0,0 @@
-<component name="ProjectCodeStyleConfiguration">
-  <code_scheme name="Project" version="173">
-    <Objective-C-extensions>
-      <file>
-        <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
-        <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
-        <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
-        <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
-        <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
-        <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
-        <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
-        <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
-        <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
-      </file>
-      <class>
-        <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
-        <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
-        <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
-        <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
-        <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
-        <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
-      </class>
-      <extensions>
-        <pair source="cpp" header="h" fileNamingConvention="NONE" />
-        <pair source="c" header="h" fileNamingConvention="NONE" />
-      </extensions>
-    </Objective-C-extensions>
-  </code_scheme>
-</component>

+ 0 - 9
.idea/modules.xml

@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="ProjectModuleManager">
-    <modules>
-      <module fileurl="file://$PROJECT_DIR$/SlimLauncher.iml" filepath="$PROJECT_DIR$/SlimLauncher.iml" />
-      <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
-    </modules>
-  </component>
-</project>

+ 0 - 12
.idea/runConfigurations.xml

@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="RunConfigurationProducerService">
-    <option name="ignoredProducers">
-      <set>
-        <option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
-        <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
-        <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
-      </set>
-    </option>
-  </component>
-</project>

+ 0 - 6
.idea/vcs.xml

@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="VcsDirectoryMappings">
-    <mapping directory="" vcs="Git" />
-  </component>
-</project>

+ 1 - 0
_config.yml

@@ -0,0 +1 @@
+theme: jekyll-theme-minimal

+ 2 - 0
app/build.gradle

@@ -65,4 +65,6 @@ dependencies {
     androidTestImplementation 'androidx.annotation:annotation:1.0.0'
     androidTestImplementation 'androidx.test:runner:1.1.0-beta02'
     androidTestImplementation 'androidx.test:rules:1.1.0-beta02'
+    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
+    androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.2'
 }

+ 3 - 3
app/src/androidTest/java/com/sduduzog/slimlauncher/DBTest.kt

@@ -25,19 +25,19 @@ class DBTest {
     fun createDb() {
         val context = InstrumentationRegistry.getTargetContext()
         mDb = Room.inMemoryDatabaseBuilder(context, AppRoomDatabase::class.java).build()
-        mAppDao = mDb!!.appDao()
+        mAppDao = mDb?.appDao()
     }
 
     @After
     fun closeDb() {
-        mDb!!.close()
+        mDb?.close()
     }
 
     @Test
     @Throws(InterruptedException::class)
     fun testInsertLiveDataApps() {
         val app = TestUtil.createApp("TestApp", "com.test.test.app", "TestMainActivity")
-        mAppDao!!.insert(app)
+        mAppDao?.insert(app)
         val appsInstalled = LiveDataTestUtil.getValue(mAppDao!!.apps)
         assertThat(appsInstalled.size, equalTo(1))
     }

+ 1 - 1
app/src/androidTest/java/com/sduduzog/slimlauncher/LiveDataTestUtil.kt

@@ -9,7 +9,7 @@ import java.util.concurrent.TimeUnit
 object LiveDataTestUtil {
 
     @Throws(InterruptedException::class)
-    fun <T> getValue(liveData: LiveData<T>): T {
+    inline fun <reified T> getValue(liveData: LiveData<T>): T {
         val data = arrayOfNulls<Any>(1)
         val latch = CountDownLatch(1)
         val observer = object : Observer<T> {

+ 67 - 0
app/src/androidTest/java/com/sduduzog/slimlauncher/SetupFragmentTest.kt

@@ -0,0 +1,67 @@
+package com.sduduzog.slimlauncher
+
+
+import android.view.View
+import android.view.ViewGroup
+import androidx.test.espresso.Espresso.onView
+import androidx.test.espresso.action.ViewActions
+import androidx.test.espresso.action.ViewActions.click
+import androidx.test.espresso.assertion.ViewAssertions.matches
+import androidx.test.espresso.matcher.RootMatchers
+import androidx.test.espresso.matcher.ViewMatchers.*
+import androidx.test.filters.LargeTest
+import androidx.test.rule.ActivityTestRule
+import androidx.test.runner.AndroidJUnit4
+import org.hamcrest.Description
+import org.hamcrest.Matcher
+import org.hamcrest.Matchers
+import org.hamcrest.Matchers.allOf
+import org.hamcrest.TypeSafeMatcher
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@LargeTest
+@RunWith(AndroidJUnit4::class)
+class SetupFragmentTest {
+
+    @Rule
+    @JvmField
+    var mActivityTestRule = ActivityTestRule(MainActivity::class.java)
+
+    @Test
+    fun isAlertDialogShown() {
+        val appCompatButton = onView(
+                allOf(withId(R.id.setupButton),
+                        withText("start"), isDisplayed()))
+        appCompatButton.perform(click())
+
+        val frameLayout = onView(
+                allOf(withId(android.R.id.content), isDisplayed()))
+        frameLayout.check(matches(isDisplayed()))
+
+        val alertDialogTitle = onView(
+                allOf(withText(R.string.choose_apps_title)))
+        alertDialogTitle.check(matches(isDisplayed()))
+    }
+
+    @Test
+    fun noAppsSelected() {
+        val appCompatButton = onView(
+                allOf(withId(R.id.setupButton), withText("start"), isDisplayed()))
+        appCompatButton.perform(click())
+
+        val appCompatButton2 = onView(
+                allOf(withId(android.R.id.button1), withText("Done")))
+        appCompatButton2.perform(ViewActions.scrollTo(), click())
+
+        val viewGroup = onView(
+                allOf(withId(R.id.setupContainer), isDisplayed()))
+        viewGroup.check(matches(isDisplayed()))
+
+        onView(withText(R.string.no_app_selected_toast_msg)).inRoot(
+                RootMatchers.withDecorView(Matchers.not(Matchers.`is`(mActivityTestRule.activity.window.decorView))))
+                .check(matches(isDisplayed()))
+    }
+
+}

+ 3 - 1
app/src/main/java/com/sduduzog/slimlauncher/ui/main/setup/SetupFragment.kt

@@ -164,11 +164,13 @@ class SetupFragment : Fragment(), DialogInteractionListener {
             }
             builder.setPositiveButton("Done") { _, _ ->
                 if (checkedItems.none { it }) {
-                    Toast.makeText(context, "Choose at least one app", Toast.LENGTH_SHORT).show()
+                    Toast.makeText(context, getString(R.string.no_app_selected_toast_msg), Toast.LENGTH_SHORT).show()
                 } else {
                     setApps()
                 }
             }
+            builder.setTitle(getString(R.string.choose_apps_title))
+
             return builder.create()
         }
 

+ 2 - 0
app/src/main/res/values/strings.xml

@@ -79,5 +79,7 @@
     <string name="settings_text_tap_to_check_between_24_hour_or_12_hour">Tap to check between 24 hour or 12 hour</string>
     <string name="settings_text_tap_to_change_app_theme">Tap to change app theme</string>
     <string name="settings_text_home_screen_apps">Home screen apps</string>
+    <string name="no_app_selected_toast_msg">Choose at least one app</string>
+    <string name="choose_apps_title">Choose Apps</string>
 
 </resources>