Skip to content

Commit

Permalink
merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
trOnk12 committed Oct 20, 2023
2 parents 0c640d6 + 9fbd124 commit 0cb734d
Show file tree
Hide file tree
Showing 45 changed files with 1,186 additions and 94 deletions.
178 changes: 178 additions & 0 deletions .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
name: Tests

on:
pull_request:
push:
branches:
- "develop"
- "main"
schedule:
# Run twice a day the sanity check, at 9:13 and 21:13.
# You ask why 13? because probably less people schedule their tasks at exactly this time, so I
# guess CI is less occupied. And 13 is a lucky number ;)
- cron: "13 9,21 * * *"

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

permissions:
contents: read
actions: read
checks: write

jobs:
unit-tests:
name: Unit Tests
runs-on: ubuntu-20.04

steps:
- name: Checkout
uses: actions/checkout@v4
with:
lfs: true

- name: Prepare Android Environment
uses: ./.github/actions/prepare-android-env

- name: Run test
run: ./gradlew test

- name: Upload tests results
if: always()
uses: actions/upload-artifact@v3
with:
name: test-results
path: |
*/build/test-results/**
*/build/paparazzi/failures/**
retention-days: 5

android-tests:
name: Run UI tests on Firebase Test Lab
runs-on: ubuntu-20.04

steps:
- name: Checkout
uses: actions/checkout@v4
with:
lfs: true

- name: LFS-warning - Prevent large files that are not LFS tracked
uses: ppremk/[email protected]

- name: Prepare Android Environment
uses: ./.github/actions/prepare-android-env

- name: Assemble App Debug APK and Android Instrumentation Tests
run: ./gradlew assembleDebug assembleDebugAndroidTest

- id: auth
name: Authenticate to Google Cloud
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.SERVICE_ACCOUNT }}

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v1
with:
install_components: "gsutil"

- name: Generate random directory
id: generate-dir
run: |-
echo "results_dir=$(date +%F_%T)-${RANDOM}" >> "$GITHUB_OUTPUT"
echo "bucket=test-lab-07qs3ns6c51bi-iazpthysivhkq" >> "$GITHUB_OUTPUT"
- name: Run tests on Firebase Test Lab
run: |-
gcloud firebase test android run ".github/tests.yml:android-pixel-2" --results-dir="${{ steps.generate-dir.outputs.results_dir }}" --results-bucket="${{ steps.generate-dir.outputs.bucket }}"
- name: Download test results from Firebase Test Lab
if: always()
run: |-
mkdir "app/build/test-results"
gsutil cp -r "gs://${{ steps.generate-dir.outputs.bucket }}/${{ steps.generate-dir.outputs.results_dir }}/Pixel2-30-en-portrait/test_result_1.xml" "app/build/test-results/results.xml"
- name: Upload tests results
if: always()
uses: actions/upload-artifact@v3
with:
name: test-results
path: |
*/build/test-results/**
retention-days: 5

test-license-headers:
name: Ensure license headers are added
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Ensure license headers are added
run: python "build-tools/check-license-headers.py"

test-results:
name: Upload tests results
runs-on: ubuntu-20.04
if: always()
needs:
- android-tests
- unit-tests

steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: build-tools/

- name: Download tests results for both jobs
uses: actions/download-artifact@v3
with:
name: test-results

- id: auth
name: Authenticate to Google Cloud
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.SERVICE_ACCOUNT }}

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Install Python dependencies
uses: py-actions/py-dependency-install@v4
with:
path: "build-tools/requirements.txt"

- name: Upload to Big Query
run: |-
if [[ "${{ github.event_name }}" != "pull_request" ]]; then
python "build-tools/upload-junit-to-cloud.py" --url "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" --final --glob "*/build/test-results/**/*.xml"
else
python "build-tools/upload-junit-to-cloud.py" --url "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" --glob "*/build/test-results/**/*.xml"
fi
- name: Test Report
uses: dorny/test-reporter@v1
with:
name: Tests Results
path: "*/build/test-results/**/*.xml"
reporter: java-junit
fail-on-error: "false"

- name: Include Slack Notification
if: github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master'
uses: ./.github/actions/slack-notification
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_GIT_REF: ${{ github.ref }}
SLACK_WORKFLOW: ${{ github.workflow }}
1 change: 1 addition & 0 deletions app-shared-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
98 changes: 98 additions & 0 deletions app-shared-tests/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
plugins {
id 'com.android.library'
id 'kotlin-kapt'
id 'org.jetbrains.kotlin.android'
id 'com.google.dagger.hilt.android'
id 'org.jlleitschuh.gradle.ktlint' version '11.2.0'
}

android {
namespace 'com.appunite.loudius'
compileSdk 33

defaultConfig {
minSdk 24
targetSdk 33
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildFeatures {
compose true
}
packagingOptions {
resources {
excludes += 'META-INF/{AL2.0,LGPL2.1}'
excludes += 'META-INF/LICENSE.md'
excludes += 'META-INF/LICENSE-notice.md'
}
}

composeOptions {
kotlinCompilerExtensionVersion '1.4.2'
}

buildTypes {
release {
minifyEnabled false
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {

implementation(project(":app"))

// Hilt
implementation "com.google.dagger:hilt-android:2.45"
kapt "com.google.dagger:hilt-compiler:2.45"
api 'com.google.dagger:hilt-android-testing:2.45'

// assertion library
// cannot use 0.34.0 due to an existing bug
// https://github.com/robfletcher/strikt/issues/259
api 'io.strikt:strikt-core:0.33.0'
api 'io.strikt:strikt-mockk:0.33.0'

// Setup Junit4 and Junit5
api(platform("org.junit:junit-bom:5.10.0"))
api("org.junit.jupiter:junit-jupiter") {
because 'allows to write and run Jupiter tests'
}
api("junit:junit:4.13.2")
runtimeOnly("org.junit.vintage:junit-vintage-engine") {
because 'allows JUnit 3 and JUnit 4 tests to run'
}
runtimeOnly("org.junit.platform:junit-platform-launcher") {
because 'allows tests to run from IDEs that bundle older version of launcher'
}

//testing
api 'androidx.test:core-ktx:1.5.0'
api 'org.robolectric:robolectric:4.10.3'
api 'androidx.test.ext:junit-ktx:1.1.5'

api "io.mockk:mockk:1.13.3"

api "com.squareup.okhttp3:mockwebserver:4.10.0"

api 'androidx.test.ext:junit:1.1.5'
api 'androidx.test.espresso:espresso-core:3.5.1'
api "androidx.compose.ui:ui-test-junit4:$compose_version"

api 'androidx.test.espresso:espresso-intents:3.5.1'

// Firebase instrumentation lib
api 'com.google.firebase:testlab-instr-lib:0.2'

// ktlint
ktlintRuleset project(":custom-ktlint-rules")
}
4 changes: 4 additions & 0 deletions app-shared-tests/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,22 @@ import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.intent.matcher.IntentMatchers.hasData
import androidx.test.espresso.intent.matcher.IntentMatchers.hasExtra
import androidx.test.espresso.intent.rule.IntentsRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.appunite.loudius.components.theme.LoudiusTheme
import com.appunite.loudius.di.GithubHelperModule
import com.appunite.loudius.ui.login.GithubHelper
import com.appunite.loudius.ui.login.LoginScreen
import com.appunite.loudius.util.ScreenshotTestRule
import dagger.hilt.android.testing.BindValue
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.UninstallModules
import io.mockk.every
import io.mockk.mockk
import org.hamcrest.Matchers.allOf
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@UninstallModules(GithubHelperModule::class)
@HiltAndroidTest
class LoginScreenTest {
abstract class AbsLoginScreenTest {

@get:Rule(order = 0)
val hiltRule = HiltAndroidRule(this)
val hiltRule by lazy { HiltAndroidRule(this) }

@get:Rule(order = 1)
val composeTestRule = createAndroidComposeRule<TestActivity>()
Expand All @@ -72,8 +63,6 @@ class LoginScreenTest {
hiltRule.inject()
}

@BindValue
@JvmField
val githubHelper: GithubHelper = mockk<GithubHelper>().apply {
every { shouldAskForXiaomiIntent() } returns false
}
Expand All @@ -90,6 +79,8 @@ class LoginScreenTest {
}

composeTestRule.onNodeWithText("Log in").performClick()

composeTestRule.waitForIdle()
intended(
allOf(
hasAction(Intent.ACTION_VIEW),
Expand All @@ -113,6 +104,7 @@ class LoginScreenTest {
composeTestRule.onNodeWithText("Log in").performClick()
composeTestRule.onNodeWithText("I've already granted").performClick()

composeTestRule.waitForIdle()
intended(
allOf(
hasAction(Intent.ACTION_VIEW),
Expand All @@ -136,6 +128,7 @@ class LoginScreenTest {
composeTestRule.onNodeWithText("Log in").performClick()
composeTestRule.onNodeWithText("Grant permission").performClick()

composeTestRule.waitForIdle()
intended(
allOf(
hasAction("miui.intent.action.APP_PERM_EDITOR"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,19 @@ package com.appunite.loudius

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.onNodeWithText
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.appunite.loudius.components.theme.LoudiusTheme
import com.appunite.loudius.ui.pullrequests.PullRequestsScreen
import com.appunite.loudius.util.IntegrationTestRule
import com.appunite.loudius.util.Register
import dagger.hilt.android.testing.HiltAndroidTest
import com.appunite.loudius.util.waitUntilLoadingDoesNotExist
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@HiltAndroidTest
class PullRequestsScreenTest {
abstract class AbsPullRequestsScreenTest {

@get:Rule
val integrationTestRule = IntegrationTestRule(this)
val integrationTestRule by lazy { IntegrationTestRule(this) }

@Before
fun setUp() {
Expand All @@ -53,6 +49,8 @@ class PullRequestsScreenTest {
}
}

composeTestRule.waitUntilLoadingDoesNotExist()

composeTestRule.onNodeWithText("First Pull-Request title").assertIsDisplayed()
}
}
Expand Down
Loading

0 comments on commit 0cb734d

Please sign in to comment.