This repository has been archived by the owner on Nov 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 712
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP: Setup integration tests (androidTest) * WIP: Setup Room migration tests * Working room DB migration configuration * Add DB migrations tests * Add migration tests for 123 to 125 * Add GitHub Action workflow that runs the integration tests * WIP: Fix Android linkage problems & the new workflow * Add missing dependency * Make the workflow run only for :ivy-data * Fix Detekt errors * Fix the Integration tests workflow #1 * Rename steps
- Loading branch information
1 parent
632aca0
commit d41c3f5
Showing
11 changed files
with
216 additions
and
28 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,45 @@ | ||
name: Integration tests (androidTest) | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
integration_test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout GIT | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Java SDK | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'adopt' | ||
java-version: '18' | ||
|
||
- name: Enable Gradle Wrapper caching (optimization) | ||
uses: actions/cache@v4 | ||
with: | ||
path: | | ||
~/.gradle/caches | ||
~/.gradle/wrapper | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
- name: Build Ivy Wallet's code | ||
run: ./gradlew ivy-data:assembleDebug ivy-data:assembleAndroidTest | ||
|
||
- name: Enable KVM (emulator optimization) | ||
run: | | ||
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules | ||
sudo udevadm control --reload-rules | ||
sudo udevadm trigger --name-match=kvm | ||
- name: Run android tests on Emulator | ||
uses: reactivecircus/android-emulator-runner@v2 | ||
with: | ||
api-level: 29 | ||
script: ./gradlew ivy-data:connectedDebugAndroidTest |
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
1 change: 0 additions & 1 deletion
1
ivy-resources/src/main/res/values/styles.xml → app/src/main/res/values/styles.xml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
plugins { | ||
id("ivy.module") | ||
id("androidx.room") | ||
} | ||
|
||
dependencies { | ||
implementation(libs.bundles.room) | ||
ksp(libs.room.compiler) | ||
|
||
androidTestImplementation(libs.room.testing) | ||
} | ||
|
||
android { | ||
sourceSets { | ||
// Adds exported schema location as test app assets. | ||
getByName("androidTest").assets.srcDirs(files("$projectDir/schemas")) | ||
} | ||
} | ||
|
||
ksp { | ||
arg("room.schemaLocation", "$projectDir/schemas") | ||
room { | ||
schemaDirectory("$projectDir/schemas") | ||
} |
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
105 changes: 105 additions & 0 deletions
105
ivy-data/src/androidTest/java/com/ivy/data/db/IvyRoomDatabaseMigrationTest.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,105 @@ | ||
package com.ivy.data.db | ||
|
||
import androidx.room.Room | ||
import androidx.room.testing.MigrationTestHelper | ||
import androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
import com.ivy.data.db.migration.Migration123to124_LoanIncludeDateTime | ||
import com.ivy.data.db.migration.Migration124to125_LoanEditDateTime | ||
import com.ivy.data.model.LoanType | ||
import io.kotest.matchers.shouldBe | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import java.util.UUID | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class IvyRoomDatabaseMigrationTest { | ||
|
||
@get:Rule | ||
val helper: MigrationTestHelper = MigrationTestHelper( | ||
InstrumentationRegistry.getInstrumentation(), | ||
IvyRoomDatabase::class.java, | ||
listOf(IvyRoomDatabase.DeleteSEMigration()), | ||
FrameworkSQLiteOpenHelperFactory() | ||
) | ||
|
||
@Test | ||
fun migrate123to125_LoanDateTime() { | ||
// given | ||
helper.createDatabase(TestDb, 123).apply { | ||
// Database has schema version 1. Insert some data using SQL queries. | ||
// You can't use DAO classes because they expect the latest schema. | ||
val insertSql = """ | ||
INSERT INTO loans (name, amount, type, color, icon, orderNum, accountId, isSynced, isDeleted, id) | ||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?); | ||
""".trimIndent() | ||
|
||
// Assuming you have an instance of LoanEntity named loanEntity | ||
val preparedStatement = compileStatement(insertSql).apply { | ||
// Bind the values from your LoanEntity instance to the prepared statement | ||
bindString(1, "Loan 1") | ||
bindDouble(2, 123.50) | ||
bindString(3, LoanType.BORROW.name) // Assuming you store enum as name | ||
bindLong(4, 13) | ||
bindString(5, "ic") | ||
bindDouble(6, 3.14) | ||
bindString(7, UUID.randomUUID().toString()) | ||
bindLong(8, 1) | ||
bindLong(9, 0) | ||
bindString(10, UUID.randomUUID().toString()) | ||
} | ||
preparedStatement.executeInsert() | ||
close() | ||
} | ||
|
||
// when | ||
helper.runMigrationsAndValidate( | ||
TestDb, | ||
124, | ||
true, | ||
Migration123to124_LoanIncludeDateTime() | ||
) | ||
val newDb = helper.runMigrationsAndValidate( | ||
TestDb, | ||
125, | ||
true, | ||
Migration124to125_LoanEditDateTime() | ||
) | ||
|
||
// then | ||
newDb.query("SELECT * FROM loans").apply { | ||
moveToFirst() shouldBe true | ||
getString(0) shouldBe "Loan 1" | ||
getDouble(1) shouldBe 123.50 | ||
getString(2) shouldBe LoanType.BORROW.name | ||
} | ||
newDb.close() | ||
} | ||
|
||
@Test | ||
fun migrateAll() { | ||
// given: | ||
// Create earliest version of the database: | ||
// for Ivy Wallet versions below 106 are broken :/ | ||
helper.createDatabase(TestDb, 106).apply { | ||
close() | ||
} | ||
|
||
// then: | ||
// Open latest version of the database. | ||
// Room validates and executes all migrations. | ||
Room.databaseBuilder( | ||
InstrumentationRegistry.getInstrumentation().targetContext, | ||
IvyRoomDatabase::class.java, | ||
TestDb | ||
).addMigrations(*IvyRoomDatabase.migrations()).build().apply { | ||
openHelper.writableDatabase.close() | ||
} | ||
} | ||
|
||
companion object { | ||
private const val TestDb = "migration-test" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,7 @@ plugins { | |
android { | ||
namespace = "com.ivy.resources" | ||
} | ||
|
||
dependencies { | ||
implementation(libs.material) | ||
} |