Skip to content

Commit

Permalink
Merge pull request #19 from NaJuDoRyeong/feature/#17-Home_TEST
Browse files Browse the repository at this point in the history
Feature/#17 home test
  • Loading branch information
KDW03 authored Sep 21, 2023
2 parents ef276dc + 63595c3 commit de984f4
Show file tree
Hide file tree
Showing 689 changed files with 1,117 additions and 239 deletions.
16 changes: 0 additions & 16 deletions .github/ci-gradle.properties
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
#
# Copyright 2020 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

org.gradle.daemon=false
org.gradle.parallel=true
org.gradle.workers.max=2
Expand Down
46 changes: 45 additions & 1 deletion .github/workflows/Build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,48 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: test-results
path: '**/build/test-results/test*UnitTest/**.xml'
path: '**/build/test-results/test*UnitTest/**.xml'

androidTest:
needs: build
runs-on: macOS-latest # enables hardware acceleration in the virtual machine
timeout-minutes: 55
strategy:
matrix:
api-level: [ 26, 30 ]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Copy CI gradle.properties
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17

- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Build AndroidTest apps
run: ./gradlew packageDemoDebug packageDemoDebugAndroidTest --daemon

- name: Run instrumentation tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
arch: x86_64
disable-animations: true
disk-size: 6000M
heap-size: 600M
script: ./gradlew connectedDemoDebugAndroidTest --daemon

- name: Upload test reports
if: always()
uses: actions/upload-artifact@v3
with:
name: test-reports-${{ matrix.api-level }}
path: '**/build/reports/androidTests'
125 changes: 125 additions & 0 deletions .idea/androidTestResultsUserPreferences.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

139 changes: 139 additions & 0 deletions app/src/androidTest/java/com/najudoryeong/mineme/DoAppStateTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package com.najudoryeong.mineme

import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.WindowSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import androidx.navigation.compose.ComposeNavigator
import androidx.navigation.compose.composable
import androidx.navigation.createGraph
import androidx.navigation.testing.TestNavHostController
import com.najudoryeong.mineme.core.testing.util.TestNetworkMonitor
import com.najudoryeong.mineme.ui.DoAppState
import com.najudoryeong.mineme.ui.rememberDoAppState
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
class DoAppStateTest {

// 테스트를 위한 규칙 정의
@get:Rule
val composeTestRule = createComposeRule()

private val networkMonitor = TestNetworkMonitor()


// 테스트 대상
private lateinit var state: DoAppState


// AppState currentDestination이 잘 동작하는지
@Test
fun doAppState_currentDestination() = runTest {
var currentDestination: String? = null

composeTestRule.setContent {
val navController = rememberTestNavController()
state = remember(navController) {
DoAppState(
navController = navController,
coroutineScope = backgroundScope,
windowSizeClass = getCompactWindowClass(),
networkMonitor = networkMonitor,
)
}

currentDestination = state.currentDestination?.route

LaunchedEffect(Unit) {
navController.setCurrentDestination("b")
}
}

assertEquals("b", currentDestination)
}


// toLevelDestination이 올바른 개수,순서인지
@Test
fun doAppState_destinations() = runTest {
composeTestRule.setContent {
state = rememberDoAppState(
windowSizeClass = getCompactWindowClass(),
networkMonitor = networkMonitor,
)
}

assertEquals(3, state.topLevelDestinations.size)
assertTrue(state.topLevelDestinations[0].name.contains("home", true))
assertTrue(state.topLevelDestinations[1].name.contains("story", true))
assertTrue(state.topLevelDestinations[2].name.contains("settings", true))
}


@Test
fun doAppState_showBottomBar_compact() = runTest {
composeTestRule.setContent {
state = DoAppState(
navController = NavHostController(LocalContext.current),
coroutineScope = backgroundScope,
windowSizeClass = getCompactWindowClass(),
networkMonitor = networkMonitor,
)
}

assertTrue(state.shouldShowBottomBar)
}

// offline 설정 잘 되는지
@Test
fun stateIsOfflineWhenNetworkMonitorIsOffline() = runTest(UnconfinedTestDispatcher()) {
composeTestRule.setContent {
state = DoAppState(
navController = NavHostController(LocalContext.current),
coroutineScope = backgroundScope,
windowSizeClass = WindowSizeClass.calculateFromSize(DpSize(900.dp, 1200.dp)),
networkMonitor = networkMonitor
)
}

backgroundScope.launch { state.isOffline.collect() }
networkMonitor.setConnected(false)
assertEquals(
true,
state.isOffline.value,
)
}

private fun getCompactWindowClass() = WindowSizeClass.calculateFromSize(DpSize(500.dp, 300.dp))
}


// TestNavHostController 설정
@Composable
private fun rememberTestNavController(): TestNavHostController {
val context = LocalContext.current
return remember {
TestNavHostController(context).apply {
navigatorProvider.addNavigator(ComposeNavigator())
graph = createGraph(startDestination = "a") {
composable("a") { }
composable("b") { }
composable("c") { }
}
}
}
}

This file was deleted.

Loading

0 comments on commit de984f4

Please sign in to comment.