Improved ObjectBoxToLibkiwixMigratorTest and clearing the application data before running the test cases.

This commit is contained in:
MohitMaliFtechiz 2024-03-19 20:57:26 +05:30
parent 39930b844e
commit 29287df550
2 changed files with 14 additions and 50 deletions

View File

@ -257,44 +257,30 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
@Test @Test
fun testLargeDataMigration(): Unit = runBlocking { fun testLargeDataMigration(): Unit = runBlocking {
// Test large data migration for recent searches // Test large data migration for recent searches
val numEntities = 1000
// Insert a large number of recent search entities into ObjectBox // Insert a large number of recent search entities into ObjectBox
(1..numEntities) for (i in 1..1000) {
.asSequence() box.put(
.map {
BookmarkEntity( BookmarkEntity(
0, 0,
expectedZimId, expectedZimId,
expectedZimName, expectedZimName,
expectedZimFilePath, expectedZimFilePath,
"https://alpine_linux/search_$it", "https://alpine_linux/search_$i",
"title_$it", "title_$i",
expectedFavicon expectedFavicon
) )
)
} }
.forEach(box::put) withContext(Dispatchers.Main) {
withContext(Dispatchers.IO) {
// Migrate data into Room database // Migrate data into Room database
objectBoxToLibkiwixMigrator.migrateBookMarks(box) objectBoxToLibkiwixMigrator.migrateBookMarks(box)
} }
// Check if data successfully migrated to Room // Check if data successfully migrated to Room
objectBoxToLibkiwixMigrator.libkiwixBookmarks.bookmarks() val actualDataAfterMigration =
.subscribeOn(Schedulers.io()) objectBoxToLibkiwixMigrator.libkiwixBookmarks.bookmarks().blockingFirst()
.observeOn(AndroidSchedulers.mainThread()) assertEquals(1000, actualDataAfterMigration.size)
.subscribe(
{ actualDataAfterMigration ->
assertEquals(numEntities, actualDataAfterMigration.size)
// Clear the bookmarks list from device to not affect the other test cases. // Clear the bookmarks list from device to not affect the other test cases.
clearBookmarks() clearBookmarks()
},
{
// Clear the bookmarks list from device to not affect the other test cases.
clearBookmarks()
throw RuntimeException(
"Exception occurred during migration. Original Exception ${it.printStackTrace()}"
)
}
)
} }
private fun clearBookmarks() { private fun clearBookmarks() {

View File

@ -4,19 +4,7 @@ adb logcat -c
# shellcheck disable=SC2035 # shellcheck disable=SC2035
adb logcat *:E -v color & adb logcat *:E -v color &
retry=0 retry=0
adb shell pm clear "org.kiwix.kiwixmobile"
PACKAGE_NAME="org.kiwix.kiwixmobile"
# Function to check if the application is installed
is_app_installed() {
adb shell pm list packages | grep -q "${PACKAGE_NAME}"
}
if is_app_installed; then
# Clear application data to properly run the test cases.
adb shell pm clear "${PACKAGE_NAME}"
fi
while [ $retry -le 3 ]; do while [ $retry -le 3 ]; do
if ./gradlew jacocoInstrumentationTestReport; then if ./gradlew jacocoInstrumentationTestReport; then
@ -29,17 +17,7 @@ while [ $retry -le 3 ]; do
# shellcheck disable=SC2035 # shellcheck disable=SC2035
adb logcat *:E -v color & adb logcat *:E -v color &
PACKAGE_NAME="org.kiwix.kiwixmobile" adb shell pm clear "org.kiwix.kiwixmobile"
# Function to check if the application is installed
is_app_installed() {
adb shell pm list packages | grep -q "${PACKAGE_NAME}"
}
if is_app_installed; then
# Clear application data to properly run the test cases.
adb shell pm clear "${PACKAGE_NAME}"
fi
./gradlew clean ./gradlew clean
retry=$(( retry + 1 )) retry=$(( retry + 1 ))
if [ $retry -eq 3 ]; then if [ $retry -eq 3 ]; then