Improved our instrumentation.sh bash script, if our test fails then after restarting the emulator if our application is installed we clear its cache data so that test cases will perform properly. We have made this change to fix a scenario that comes locally after testing so many times where downloading is stuck due to lag of emulator.

* * Improved the LibkiwixBookmarkTest. In this, before performing the test case we are removing the existing bookmarks if any so that the saved bookmark will not go outside the screen(We faced an occurrence of this type locally).
* Improved the ZIM file path in many scenarios so that the created ZIM file will show in the LocalLibraryScreen and we can delete it so that we can free up the memory.
This commit is contained in:
MohitMaliFtechiz 2024-03-06 18:33:27 +05:30
parent d5305b6856
commit 606bea4405
9 changed files with 63 additions and 8 deletions

View File

@ -18,6 +18,7 @@
package org.kiwix.kiwixmobile
import androidx.core.content.ContextCompat
import androidx.core.content.edit
import androidx.lifecycle.Lifecycle
import androidx.preference.PreferenceManager
@ -122,7 +123,10 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
// add a file in fileSystem because we need to actual file path for making object of Archive.
val loadFileStream =
ObjectBoxToLibkiwixMigratorTest::class.java.classLoader.getResourceAsStream("testzim.zim")
zimFile = File(context.cacheDir, "testzim.zim")
zimFile = File(
ContextCompat.getExternalFilesDirs(context, null)[0],
"testzim.zim"
)
if (zimFile.exists()) zimFile.delete()
zimFile.createNewFile()
loadFileStream.use { inputStream ->
@ -306,6 +310,7 @@ class ObjectBoxToLibkiwixMigratorTest : BaseActivityTest() {
.blockingFirst() as List<LibkiwixBookmarkItem>
)
box.removeAll()
zimFile.delete() // delete the temp ZIM file to free up the memory
}
@After

View File

@ -18,6 +18,7 @@
package org.kiwix.kiwixmobile.mimetype
import androidx.core.content.ContextCompat
import androidx.core.content.edit
import androidx.lifecycle.Lifecycle
import androidx.preference.PreferenceManager
@ -63,7 +64,10 @@ class MimeTypeTest : BaseActivityTest() {
@Test
fun testMimeType() {
val loadFileStream = MimeTypeTest::class.java.classLoader.getResourceAsStream("testzim.zim")
val zimFile = File(context.cacheDir, "testzim.zim")
val zimFile = File(
ContextCompat.getExternalFilesDirs(context, null)[0],
"testzim.zim"
)
if (zimFile.exists()) zimFile.delete()
zimFile.createNewFile()
loadFileStream.use { inputStream ->

View File

@ -53,6 +53,15 @@ class BookmarksRobot : BaseRobot() {
isVisible(TextId(R.string.delete_bookmarks))
}
fun clickOnDeleteButton() {
pauseForBetterTestPerformance()
onView(withText("DELETE")).perform(click())
}
fun assertNoBookMarkTextDisplayed() {
isVisible(TextId(R.string.no_bookmarks))
}
fun clickOnSaveBookmarkImage() {
pauseForBetterTestPerformance()
clickOn(ViewId(R.id.bottom_toolbar_bookmark))

View File

@ -18,6 +18,7 @@
package org.kiwix.kiwixmobile.page.bookmarks
import androidx.core.content.ContextCompat
import androidx.core.content.edit
import androidx.core.net.toUri
import androidx.lifecycle.Lifecycle
@ -75,7 +76,10 @@ class LibkiwixBookmarkTest : BaseActivityTest() {
}
val loadFileStream =
LibkiwixBookmarkTest::class.java.classLoader.getResourceAsStream("testzim.zim")
val zimFile = File(context.cacheDir, "testzim.zim")
val zimFile = File(
ContextCompat.getExternalFilesDirs(context, null)[0],
"testzim.zim"
)
if (zimFile.exists()) zimFile.delete()
zimFile.createNewFile()
loadFileStream.use { inputStream ->
@ -96,6 +100,13 @@ class LibkiwixBookmarkTest : BaseActivityTest() {
)
}
bookmarks {
// delete any bookmark if already saved to properly perform this test case.
longClickOnSaveBookmarkImage()
clickOnTrashIcon()
assertDeleteBookmarksDialogDisplayed()
clickOnDeleteButton()
assertNoBookMarkTextDisplayed()
pressBack()
// Test saving bookmark
clickOnSaveBookmarkImage()
clickOnOpenSavedBookmarkButton()

View File

@ -18,6 +18,7 @@
package org.kiwix.kiwixmobile.page.history
import androidx.core.content.ContextCompat
import androidx.core.content.edit
import androidx.core.net.toUri
import androidx.lifecycle.Lifecycle
@ -78,7 +79,10 @@ class NavigationHistoryTest : BaseActivityTest() {
}
val loadFileStream =
NavigationHistoryTest::class.java.classLoader.getResourceAsStream("testzim.zim")
val zimFile = File(context.cacheDir, "testzim.zim")
val zimFile = File(
ContextCompat.getExternalFilesDirs(context, null)[0],
"testzim.zim"
)
if (zimFile.exists()) zimFile.delete()
zimFile.createNewFile()
loadFileStream.use { inputStream ->

View File

@ -18,6 +18,7 @@
package org.kiwix.kiwixmobile.reader
import androidx.core.content.ContextCompat
import androidx.core.content.edit
import androidx.core.net.toUri
import androidx.lifecycle.Lifecycle
@ -77,7 +78,10 @@ class KiwixReaderFragmentTest : BaseActivityTest() {
}
val loadFileStream =
KiwixReaderFragmentTest::class.java.classLoader.getResourceAsStream("testzim.zim")
val zimFile = File(context.cacheDir, "testzim.zim")
val zimFile = File(
ContextCompat.getExternalFilesDirs(context, null)[0],
"testzim.zim"
)
if (zimFile.exists()) zimFile.delete()
zimFile.createNewFile()
loadFileStream.use { inputStream ->

View File

@ -17,6 +17,7 @@
*/
package org.kiwix.kiwixmobile.search
import androidx.core.content.ContextCompat
import androidx.core.content.edit
import androidx.core.net.toUri
import androidx.lifecycle.Lifecycle
@ -216,7 +217,10 @@ class SearchFragmentTest : BaseActivityTest() {
private fun getTestZimFile(): File {
val loadFileStream =
SearchFragmentTest::class.java.classLoader.getResourceAsStream("testzim.zim")
val zimFile = File(context.cacheDir, "testzim.zim")
val zimFile = File(
ContextCompat.getExternalFilesDirs(context, null)[0],
"testzim.zim"
)
if (zimFile.exists()) zimFile.delete()
zimFile.createNewFile()
loadFileStream.use { inputStream ->

View File

@ -152,6 +152,9 @@ class ZimHostFragmentTest {
// Check that only one ZIM file is hosted on the server after unselecting
assertItemHostedOnServer(1)
// finally close the server at the end of test case
stopServer()
}
LeakAssertions.assertNoLeaks()
}

View File

@ -6,8 +6,7 @@ adb logcat -c
# shellcheck disable=SC2035
adb logcat *:E -v color &
retry=0
while [ $retry -le 3 ]
do
while [ $retry -le 3 ]; do
if ./gradlew jacocoInstrumentationTestReport; then
echo "jacocoInstrumentationTestReport succeeded" >&2
break
@ -19,6 +18,18 @@ do
adb logcat -c
# shellcheck disable=SC2035
adb logcat *:E -v color &
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
./gradlew clean
retry=$(( retry + 1 ))
if [ $retry -eq 3 ]; then