generated from cgpathos/template-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [#13] 모듈별로 테스트 트리거되도록 분리(common,data), 테스트 코드 추가 * [#13] workflow 이름 수정 * [#13] data, common test 트리거 검증 * [#13] test 트리거 조건 조정 * [#13] job 이름 조정
- Loading branch information
Showing
12 changed files
with
180 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: module_common | ||
|
||
on: | ||
push: | ||
branches: | ||
- '**' | ||
paths: | ||
- "common/**" | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.pull_request.number }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
common: | ||
uses: ./.github/workflows/test.yml | ||
with: | ||
module: 'common' | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: module_data | ||
|
||
on: | ||
push: | ||
branches: | ||
- '**' | ||
paths: | ||
- "data/**" | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.pull_request.number }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
data: | ||
uses: ./.github/workflows/test.yml | ||
with: | ||
module: 'data' | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
common/src/test/java/today/pathos/android/portfolio/common/result/ResultKtTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package today.pathos.android.portfolio.common.result | ||
|
||
import app.cash.turbine.test | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
class ResultKtTest { | ||
|
||
@Test | ||
fun asResultError() = runTest { | ||
flow { | ||
emit(1) | ||
throw Throwable("Some Error") | ||
}.asResult() | ||
.test { | ||
assertEquals(Result.Loading, awaitItem()) | ||
assertEquals(Result.Success(1), awaitItem()) | ||
|
||
when (val error = awaitItem()) { | ||
is Result.Error -> assertEquals( | ||
"Some Error", | ||
error.e.message | ||
) | ||
|
||
Result.Loading, | ||
is Result.Success, | ||
-> { | ||
throw IllegalStateException("Flow should have emitted an Result.Error") | ||
} | ||
} | ||
|
||
awaitComplete() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...droidTest/java/today/pathos/android/portfolio/data/datasource/local/db/dao/FameDaoTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package today.pathos.android.portfolio.data.datasource.local.db.dao | ||
|
||
import app.cash.turbine.test | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import today.pathos.android.portfolio.data.datasource.local.db.rule.DatabaseRule | ||
import today.pathos.android.portfolio.data.datasource.local.db.table.FameTbl | ||
|
||
class FameDaoTest { | ||
@get:Rule | ||
val rule = DatabaseRule() | ||
|
||
private val fameDao = rule.database.fameDao() | ||
|
||
@Before | ||
fun setUp() { | ||
createTestData() | ||
} | ||
|
||
private fun createTestData() = runTest { | ||
val testData = listOf( | ||
FameTbl( | ||
serverId = "SERVER_ID1", | ||
characterId = "CHARACTER_ID", | ||
characterName = "CHARACTER_NAME_1", | ||
level = 99, | ||
jobId = "JOB_ID", | ||
jobGrowId = "JOB_GROW_ID", | ||
jobName = "JOB_NAME", | ||
jobGrowName = "JOB_GROW_NAME", | ||
fame = 999, | ||
), | ||
FameTbl( | ||
serverId = "SERVER_ID2", | ||
characterId = "CHARACTER_ID", | ||
characterName = "CHARACTER_NAME", | ||
level = 99, | ||
jobId = "JOB_ID", | ||
jobGrowId = "JOB_GROW_ID", | ||
jobName = "JOB_NAME", | ||
jobGrowName = "JOB_GROW_NAME", | ||
fame = 999, | ||
), | ||
) | ||
fameDao.createFame(testData) | ||
} | ||
|
||
@Test | ||
fun fameListCount() = runTest { | ||
val fameListCount = fameDao.fameListCount() | ||
val expectedCount = 2 | ||
assertEquals(expectedCount, fameListCount) | ||
} | ||
|
||
@Test | ||
fun firstFameInFameList() = runTest { | ||
val expectedFirstCharacterName = "CHARACTER_NAME_1" | ||
|
||
fameDao.getFameList() | ||
.test { | ||
assertEquals(expectedFirstCharacterName, awaitItem().first().characterName) | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...oidTest/java/today/pathos/android/portfolio/data/datasource/local/db/rule/DatabaseRule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package today.pathos.android.portfolio.data.datasource.local.db.rule | ||
|
||
import androidx.room.Room | ||
import androidx.test.core.app.ApplicationProvider | ||
import org.junit.rules.TestWatcher | ||
import org.junit.runner.Description | ||
import today.pathos.android.portfolio.data.datasource.local.db.CacheDatabase | ||
|
||
class DatabaseRule : TestWatcher() { | ||
val database = Room.inMemoryDatabaseBuilder( | ||
ApplicationProvider.getApplicationContext(), | ||
CacheDatabase::class.java | ||
).allowMainThreadQueries() | ||
.build() | ||
|
||
override fun finished(description: Description?) { | ||
super.finished(description) | ||
database.close() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters