Skip to content
This repository has been archived by the owner on Jun 7, 2020. It is now read-only.

[NEW] Improve test automation in Rocket Chat Android Repo #2465

Open
wants to merge 121 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
c81708d
Update circle.ci config file to run UI tests
GOVINDDIXIT May 23, 2019
2f9ac92
feat: add test dependencies
GOVINDDIXIT May 23, 2019
bb31d73
Update config.yml
GOVINDDIXIT May 24, 2019
a0e7f5a
minor changes
GOVINDDIXIT May 24, 2019
689a388
Create RunUITests.md
GOVINDDIXIT May 24, 2019
11ae80d
update HowToRunTests.md and remove unused imports
GOVINDDIXIT May 26, 2019
92e240e
add unit tests
GOVINDDIXIT May 27, 2019
a82554a
update config
GOVINDDIXIT May 30, 2019
ec1a4ee
add ui tests:
GOVINDDIXIT Jun 1, 2019
c674149
fix merge conflicts
GOVINDDIXIT Jun 2, 2019
9266b74
fix: ui test not running on circleci
GOVINDDIXIT Jun 2, 2019
f6c35cd
remove extra lines
GOVINDDIXIT Jun 4, 2019
1084488
catch RC upstream
GOVINDDIXIT Jun 4, 2019
40df976
add config file and update readme
GOVINDDIXIT Jun 9, 2019
b6fb1ff
modify existing tests
GOVINDDIXIT Jun 9, 2019
91293a8
add new tests
GOVINDDIXIT Jun 9, 2019
f49442f
fix tests
GOVINDDIXIT Jun 9, 2019
d756aed
minor fixes
GOVINDDIXIT Jun 9, 2019
73d5e39
use static variables
GOVINDDIXIT Jun 9, 2019
02c1f27
catch RC upstream
GOVINDDIXIT Jun 10, 2019
30afe4f
Add test for loginOptionFragment
GOVINDDIXIT Jun 11, 2019
cf5c318
Update
GOVINDDIXIT Jun 12, 2019
b9a0142
minor changes
GOVINDDIXIT Jun 16, 2019
b2fc718
minor changes
GOVINDDIXIT Jun 17, 2019
e060575
update ui tests
GOVINDDIXIT Jun 17, 2019
0e68cf1
update
GOVINDDIXIT Jun 17, 2019
e34053d
refactor
GOVINDDIXIT Jun 18, 2019
78f975a
update config file
GOVINDDIXIT Jun 18, 2019
0b98db9
remove hardcoded string
GOVINDDIXIT Jun 19, 2019
38b31d4
feat: add espresso contrib
GOVINDDIXIT Jun 24, 2019
d47f68d
feat: add ui tests
GOVINDDIXIT Jun 24, 2019
d435cfb
Merge pull request #9 from GOVINDDIXIT/authentication_tests
GOVINDDIXIT Jun 24, 2019
766a0d5
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.A…
GOVINDDIXIT Jun 27, 2019
125249b
feat: update ui tests
GOVINDDIXIT Jun 27, 2019
a9a763b
tests: channelFragment and member module
GOVINDDIXIT Jun 30, 2019
89306ef
Merge pull request #10 from GOVINDDIXIT/profile_userdetails_tests
GOVINDDIXIT Jul 2, 2019
5a76a75
Merge pull request #11 from GOVINDDIXIT/create_channel_members_tests
GOVINDDIXIT Jul 2, 2019
daa9942
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.A…
GOVINDDIXIT Jul 2, 2019
b46b9f9
Merge branch 'develop' of https://github.com/GOVINDDIXIT/Rocket.Chat.…
GOVINDDIXIT Jul 2, 2019
509411c
test: setting module
GOVINDDIXIT Jul 4, 2019
f306e7f
update tests
GOVINDDIXIT Jul 5, 2019
df1769a
update tests
GOVINDDIXIT Jul 5, 2019
f515fa2
test: mention and favorite message module
GOVINDDIXIT Jul 6, 2019
f1ab230
update
GOVINDDIXIT Jul 7, 2019
034851a
tests: server module
GOVINDDIXIT Jul 7, 2019
ab3dcad
update tests
GOVINDDIXIT Jul 11, 2019
75963a5
update
GOVINDDIXIT Jul 12, 2019
a82d1ba
tests: sorting and grouping module
GOVINDDIXIT Jul 12, 2019
69972d3
chore: remove run ui-test script
GOVINDDIXIT Jul 12, 2019
872f900
Merge pull request #13 from GOVINDDIXIT/mention_favorite_message_tests
GOVINDDIXIT Jul 16, 2019
3cd7bbe
Merge branch 'develop' into settings_tests
GOVINDDIXIT Jul 16, 2019
11536e0
tests: fixes
GOVINDDIXIT Jul 16, 2019
6ec98cc
Merge branch 'settings_tests' of https://github.com/GOVINDDIXIT/Rocke…
GOVINDDIXIT Jul 16, 2019
858222d
fix typo
GOVINDDIXIT Jul 16, 2019
0cc0eee
tests: fixes
GOVINDDIXIT Jul 17, 2019
3f1cf44
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.A…
GOVINDDIXIT Jul 18, 2019
295ad1e
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.A…
GOVINDDIXIT Jul 19, 2019
f92359d
remove run ui test script
GOVINDDIXIT Jul 19, 2019
1991c06
tests: Directory module
GOVINDDIXIT Jul 19, 2019
2616d48
tests: Files module
GOVINDDIXIT Jul 19, 2019
5a4d423
remove run ui test script
GOVINDDIXIT Jul 19, 2019
932db10
fix: unit tests according to upstream code changes
GOVINDDIXIT Jul 19, 2019
2a7eec6
fix: UI tests according to upstream code changes
GOVINDDIXIT Jul 20, 2019
dba0999
fix unit test
GOVINDDIXIT Jul 23, 2019
ffab151
tests: update tests in authentication module
GOVINDDIXIT Jul 23, 2019
6b1f515
fix unit test
GOVINDDIXIT Jul 23, 2019
8b66923
tests: update tests in authentication module
GOVINDDIXIT Jul 23, 2019
a6bc1e1
update codecov
GOVINDDIXIT Jul 23, 2019
b3a61bf
update codecov
GOVINDDIXIT Jul 23, 2019
c643034
update codecov
GOVINDDIXIT Jul 23, 2019
c75c9c6
update codecov
GOVINDDIXIT Jul 23, 2019
1e3abe1
unit tests: twoFA module
GOVINDDIXIT Jul 23, 2019
becc4e7
unit test: ResetPassword module
GOVINDDIXIT Jul 23, 2019
04c5267
Merge pull request #12 from GOVINDDIXIT/settings_tests
GOVINDDIXIT Jul 23, 2019
9915e01
Merge branch 'develop' into directory_files_tests
GOVINDDIXIT Jul 24, 2019
576021b
Merge pull request #15 from GOVINDDIXIT/directory_files_tests
GOVINDDIXIT Jul 24, 2019
be4e136
Merge branch 'develop' of https://github.com/GOVINDDIXIT/Rocket.Chat.…
GOVINDDIXIT Jul 24, 2019
a4156d8
tests: chatrooms module
GOVINDDIXIT Jul 25, 2019
c011ab2
tests: chatdetails module
GOVINDDIXIT Jul 27, 2019
ffa6a10
tests: chatrooms module
GOVINDDIXIT Jul 27, 2019
ffdf70c
tests: chatroom module
GOVINDDIXIT Jul 28, 2019
daeec40
update
GOVINDDIXIT Jul 29, 2019
715bd13
unit test: main module
GOVINDDIXIT Aug 1, 2019
2ac3853
unit test: main module
GOVINDDIXIT Aug 1, 2019
af8957b
update
GOVINDDIXIT Aug 1, 2019
a00569f
unit test: sorting and grouping module
GOVINDDIXIT Aug 1, 2019
9e0da74
update
GOVINDDIXIT Aug 2, 2019
8a8f663
tests: inviteUser module
GOVINDDIXIT Aug 2, 2019
dab2ec2
tests: password module
GOVINDDIXIT Aug 2, 2019
42bad04
update
GOVINDDIXIT Aug 2, 2019
4a0af6b
unit test: chatDetails module
GOVINDDIXIT Aug 4, 2019
0ef5262
update
GOVINDDIXIT Aug 8, 2019
3077d41
Merge branch 'develop' into chatroom_chatrooms_tests
GOVINDDIXIT Aug 8, 2019
98a1499
update
GOVINDDIXIT Aug 9, 2019
acee0af
refactor and fix flakes tests
GOVINDDIXIT Aug 8, 2019
b4c6808
refactor and update readme
GOVINDDIXIT Aug 10, 2019
23f510e
Merge pull request #17 from GOVINDDIXIT/chatroom_chatrooms_tests
GOVINDDIXIT Aug 10, 2019
ed9710e
Merge branch 'develop' of https://github.com/GOVINDDIXIT/Rocket.Chat.…
GOVINDDIXIT Aug 10, 2019
bb784fc
fix merge conflicts
GOVINDDIXIT Aug 10, 2019
58d0ef3
requested changes
GOVINDDIXIT Aug 10, 2019
72eab5f
Merge branch 'develop' into tests
GOVINDDIXIT Aug 12, 2019
5dc6522
requested changes
GOVINDDIXIT Aug 14, 2019
80df548
refactor and remove coroutines tests
GOVINDDIXIT Aug 12, 2019
5ae7e12
remove redundant code
GOVINDDIXIT Aug 14, 2019
188a3e9
remove hardcoded string
GOVINDDIXIT Aug 15, 2019
b75597f
remove extra lines and unused imports
GOVINDDIXIT Aug 15, 2019
06ceaa7
Merge pull request #18 from GOVINDDIXIT/password_invite_users
GOVINDDIXIT Aug 15, 2019
61c71ea
Merge branch 'develop' into tests
GOVINDDIXIT Aug 15, 2019
bf83024
Merge pull request #16 from GOVINDDIXIT/tests
GOVINDDIXIT Aug 15, 2019
1709991
ui tests: registerUsername module
GOVINDDIXIT Aug 16, 2019
5c28b8d
ui tests: MessageInfo module
GOVINDDIXIT Aug 16, 2019
dbabbde
ui tests: AdminPanelWebView
GOVINDDIXIT Aug 16, 2019
3d75bf3
ui tests: update old tests
GOVINDDIXIT Aug 16, 2019
58502de
ui tests: add settingFragmentIntentTests
GOVINDDIXIT Aug 16, 2019
0295a13
ui tests: update old tests
GOVINDDIXIT Aug 16, 2019
66ae1cb
Update HOW_TO_RUN_TESTS.md
GOVINDDIXIT Aug 18, 2019
d3c3971
Merge pull request #19 from GOVINDDIXIT/ui_tests
GOVINDDIXIT Aug 23, 2019
0b51e73
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat.A…
GOVINDDIXIT Aug 23, 2019
7bb3892
update
GOVINDDIXIT Aug 23, 2019
c8e5a6c
Merge branch 'develop' into develop
GOVINDDIXIT Aug 25, 2019
da06833
Update config.yml
GOVINDDIXIT Aug 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- store_artifacts:
path: app/libs/
destination: libs
code-analysis:
run-unit-tests:
docker:
- image: circleci/android:api-29
environment:
Expand All @@ -55,14 +55,17 @@ jobs:
- ~/.gradle/wrapper
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}-{{ checksum "player/build.gradle" }}-{{ checksum "core/build.gradle" }}-{{ checksum "util/build.gradle" }}-{{ checksum "draw/build.gradle" }}-{{ checksum "emoji/build.gradle" }}-{{ checksum "suggestions/build.gradle" }}
- run:
name: Run Lint
name: Run Lint
command: ./gradlew lint
- run:
name: Run Unit test
command: ./gradlew test
command: ./gradlew --no-daemon testPlayDebugUnitTest
- run:
name: Compile Instrumentation test
command: ./gradlew assembleAndroidTest
name: Generate reports
command: ./gradlew jacocoTestPlayDebugUnitTestReport
- run:
name: Send coverage
command: bash <(curl -s https://codecov.io/bash)
- store_artifacts:
path: app/build/reports/
destination: reports
Expand Down Expand Up @@ -143,13 +146,12 @@ workflows:
build-deploy:
jobs:
- build-kotlin-sdk
- code-analysis:
- run-unit-tests:
requires:
- build-kotlin-sdk
filters:
branches:
ignore: # skip on merge commits.
- develop
- develop-2.x
- master
- build-aab:
Expand Down
28 changes: 28 additions & 0 deletions HOW_TO_RUN_TESTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
### How to run Unit tests and UI tests on local machine

#### Unit tests

1. Fork the repo and setup the project on your local machine.
2. Open Android Studio terminal
3. Run gradlew test

#### UI tests

1. Fork the repo and setup the project on your local machine.
2. Open Android Studio terminal and run the android emulator.
3. Run gradlew connectedAndroidTest command on your AS Terminal (To run Android tests on each module and build variant in the project)
4. Run gradlew connectedPlayDebugAndroidTest (for specific play variant)

**Note:**
1. Before running UI tests on the emulator device uninstall the existing version of RC app from it.
2. It is advised to turn off all the animation of device, tests may fail if animations are on. To turn the animations off go to developer
option in device settings.
3. It is advised to have good network connection and sufficient ram in you machine while running the UI tests


### Any organization that forks RC can run tests against their own server
- Organisation using Rocket.Chat fork can also run the tests by doing some minor changes.
- For tests to work properly, Organisations have to follow the instructions mentioned in [Config file](https://github.com/GOVINDDIXIT/Rocket.Chat.Android/blob/develop/app/src/main/java/testConfig/Config.kt) carefully which also include creating new user.
- They have to create additional channels as mentioned in the config file.
- Also they need to customise the links present in the config file according to their server requirements.

37 changes: 37 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: "com.github.ben-manes.versions"
apply plugin: 'jacoco-android'

android {
compileSdkVersion versions.compileSdk
Expand Down Expand Up @@ -39,6 +40,35 @@ android {
}
}

kapt {
useBuildCache true
}

dexOptions {
preDexLibraries true
jumboMode false
}

testOptions {
unitTests.all {
jacoco {
includeNoLocationClasses = true
}
}
unitTests{
includeAndroidResources = true
returnDefaultValues = true
}
}

tasks.withType(Test) {
testLogging {
exceptionFormat "full"
events "passed", "failed"
showStandardStreams true
}
}

signingConfigs {
release {
storeFile project.rootProject.file('Rocket.jks').getCanonicalFile()
Expand Down Expand Up @@ -69,6 +99,7 @@ android {
buildConfigField "String", "RECOMMENDED_SERVER_VERSION", '"0.64.2"'
signingConfig signingConfigs.debug
applicationIdSuffix ".dev"
testCoverageEnabled true
}
}

Expand Down Expand Up @@ -180,6 +211,12 @@ dependencies {
testImplementation libraries.truth
androidTestImplementation libraries.espressoCore
androidTestImplementation libraries.espressoIntents
androidTestImplementation libraries.espressoContrib
androidTestImplementation libraries.uiAutomator
testImplementation libraries.mockito
testImplementation libraries.mockitoInline
androidTestImplementation libraries.mockitoAndroid
androidTestImplementation libraries.runner
}

androidExtensions {
Expand Down
20 changes: 20 additions & 0 deletions app/jacoco.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apply plugin: 'jacoco'

task jacocoTestReport(type: JacocoReport, dependsOn: ['testPlayDebugUnitTest', 'createPlayDebugCoverageReport']) {

reports {
xml.enabled = true
html.enabled = true
}

def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter)
def mainSrc = "${project.projectDir}/src/main/java"

sourceDirectories = files([mainSrc])
classDirectories = files([debugTree])
executionData = fileTree(dir: "$buildDir", includes: [
"jacoco/testPlayDebugUnitTest.exec",
"outputs/code-coverage/playDebugAndroidTest/connected/*coverage.ec"
])
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package chat.rocket.android.authentication.login.ui

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.*
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.filters.LargeTest
import androidx.test.rule.ActivityTestRule
import chat.rocket.android.R
import chat.rocket.android.analytics.event.ScreenViewEvent
import chat.rocket.android.authentication.ui.AuthenticationActivity
import chat.rocket.android.util.withHint
import chat.rocket.android.util.extensions.addFragmentBackStack
import org.hamcrest.Matchers.not
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import testConfig.Config.Companion.PASSWORD
import testConfig.Config.Companion.SERVER_URL
import testConfig.Config.Companion.USERNAME

@LargeTest
class LoginFragmentTest {

@JvmField
var activityRule = ActivityTestRule(AuthenticationActivity::class.java, true, true)

@Rule
fun rule() = activityRule

@Before
fun setUp() {
rule().activity.addFragmentBackStack(ScreenViewEvent.Login.screenName, R.id.fragment_container) {
newInstance(SERVER_URL)
}
}

@Test
fun check_UI_elements(){
onView(withId(R.id.text_login)).check(matches(withText("Login")))
onView(withId(R.id.text_username_or_email)).check(matches(withHint("Username or email")))
onView(withId(R.id.text_password)).check(matches(withHint("Password")))
onView(withId(R.id.button_log_in)).check(matches(withText("Login")))
onView(withId(R.id.button_forgot_your_password)).check(matches(withText("Forgot your password?")))
}

@Test
fun login_button_enable_if_details_are_filled(){
onView(withId(R.id.text_username_or_email)).perform(
typeText(USERNAME), closeSoftKeyboard()
)
onView(withId(R.id.text_password)).perform(
typeText(PASSWORD), closeSoftKeyboard()
)
onView(withId(R.id.button_log_in)).check(matches(isEnabled()))
}

@Test
fun login_button_disable_if_details_are_not_filled(){
onView(withId(R.id.text_username_or_email)).perform(
typeText(USERNAME), closeSoftKeyboard()
)
onView(withId(R.id.button_log_in)).check(matches(not(isEnabled())))
}

@Test
fun check_login_with_email_and_logout(){
onView(withId(R.id.text_username_or_email)).perform(
typeText(USERNAME), closeSoftKeyboard()
)
onView(withId(R.id.text_password)).perform(
typeText(PASSWORD), closeSoftKeyboard()
)
onView(withId(R.id.button_log_in)).perform(click())
Thread.sleep(15000)
onView(withContentDescription(R.string.abc_action_bar_up_description)).perform(click())
Thread.sleep(2000)
onView(withId(R.id.text_logout)).check(matches(isDisplayed()))
.perform(click())
onView(withText("LOGOUT")).perform(click())
Thread.sleep(2000)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package chat.rocket.android.authentication.loginoptions.ui

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.scrollTo
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.filters.LargeTest
import androidx.test.rule.ActivityTestRule
import chat.rocket.android.R
import chat.rocket.android.authentication.ui.AuthenticationActivity
import org.junit.Before
import org.junit.Rule
import org.junit.Test

@LargeTest
class LoginOptionsFragmentTest {

@Rule
@JvmField
var activityRule = ActivityTestRule<AuthenticationActivity>(AuthenticationActivity::class.java)

@Before
fun setUp() {
onView(withId(R.id.join_community_container))
.perform(scrollTo(), click())
Thread.sleep(5000)
}

@Test
fun check_UI_element() {
onView(withId(R.id.button_facebook)).check(matches(withText("Continue with Facebook")))
onView(withId(R.id.button_google)).check(matches(withText("Continue with Google")))
onView(withId(R.id.button_gitlab)).check(matches(withText("Continue with GitLab")))
}

@Test
fun expand_collapse_accounts_and_check_UI_elements() {
onView(withId(R.id.button_expand_collapse_accounts))
.perform(scrollTo(), click())
onView(withId(R.id.button_linkedin)).check(matches(withText("Continue with LinkedIn")))
onView(withId(R.id.button_github)).check(matches(withText("Continue with GitHub")))
}

@Test
fun click_login_with_email() {
onView(withId(R.id.button_login_with_email)).check(matches(withText("Login with e-mail")))
.perform(scrollTo(), click())
onView(withId(R.id.text_login)).check(matches(withText("Login")))
}

@Test
fun check_create_an_account() {
onView(withId(R.id.button_create_an_account)).check(matches(withText("Create an account")))
.perform(scrollTo(), click())
onView(withId(R.id.text_sign_up)).check(matches(withText("Sign up")))
}

@Test
fun check_facebook_button() {
onView(withId(R.id.button_facebook))
.perform(scrollTo(), click())
onView(withId(R.id.web_view)).check(matches(isDisplayed()))
}

@Test
fun check_github_button() {
onView(withId(R.id.button_github))
.perform(scrollTo(), click())
onView(withId(R.id.web_view)).check(matches(isDisplayed()))
}

@Test
fun check_google_button() {
onView(withId(R.id.button_google)).perform(scrollTo())
.perform(scrollTo(), click())
onView(withId(R.id.web_view)).check(matches(isDisplayed()))
}

@Test
fun check_linkedin_button() {
onView(withId(R.id.button_expand_collapse_accounts))
.perform(scrollTo(), click())
onView(withId(R.id.button_linkedin))
.perform(scrollTo(), click())
onView(withId(R.id.web_view)).check(matches(isDisplayed()))
}

@Test
fun check_gitlab_button() {
onView(withId(R.id.button_expand_collapse_accounts))
.perform(scrollTo(), click())
onView(withId(R.id.button_gitlab))
.perform(scrollTo(), click())
onView(withId(R.id.web_view)).check(matches(isDisplayed()))
}
}
Loading