Skip to content

Commit

Permalink
Test: Add unit test using robolectric
Browse files Browse the repository at this point in the history
This patch adds android unit test.
Using robolectric, tests run inside the JVM.
model list has mobilenet, yolov8 now, so itemCount will be 2.

Signed-off-by: Yelin Jeong <[email protected]>
  • Loading branch information
niley7464 authored and wooksong committed Jun 25, 2024
1 parent a9eb562 commit e44d066
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ espressoCore = "3.5.1"
lifecycleRuntimeKtx = "2.7.0"
activityCompose = "1.8.2"
composeBom = "2024.04.00"
robolectric = "4.12.2"

[libraries]
tukaani-xz ={ group = "org.tukaani", name= "xz", version.ref = "tukaani-xz-plugin" }
Expand All @@ -32,6 +33,7 @@ androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-toolin
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
robolectric = { module = "org.robolectric:robolectric", version.ref = "robolectric" }

[plugins]
xyz-simple-git = { id = "xyz.ronella.simple-git", version.ref = "xyz-simple-git-plugin" }
Expand Down
8 changes: 7 additions & 1 deletion ml_inference_offloading/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
Expand Down Expand Up @@ -47,6 +47,11 @@ android {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
testOptions {
unitTests {
isIncludeAndroidResources = true
}
}
}

dependencies {
Expand All @@ -61,6 +66,7 @@ dependencies {
implementation(project(":nnstreamer-api"))
implementation("androidx.recyclerview:recyclerview:1.3.2")
testImplementation(libs.junit)
testImplementation(libs.robolectric)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ai.nnstreamer.ml.inference.offloading


import androidx.recyclerview.widget.RecyclerView

import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner

@RunWith(RobolectricTestRunner::class)
class ActivityUnitTest {
@Test
fun testModelListLength() {
val activityController = Robolectric.buildActivity(MainActivity::class.java).create()
val activity = activityController.get()
val recyclerview = activity.findViewById<RecyclerView>(R.id.model_list)
val adapter = recyclerview.adapter

adapter?.run {
assertEquals(2, adapter.itemCount)
}
}
}

This file was deleted.

0 comments on commit e44d066

Please sign in to comment.