Ivan
01/20/2025, 3:14 PMOpenCVLoader.initLocal()
in my tests
ImageQualityTest > testImageQuality FAILED
java.lang.RuntimeException: Method d in android.util.Log not mocked. See <https://developer.android.com/r/studio-ui/build/not-mocked> for details.
at android.util.Log.d(Log.java)
at org.opencv.android.StaticHelper.initOpenCV(StaticHelper.java:18)
at org.opencv.android.OpenCVLoader.initLocal(OpenCVLoader.java:31)
at com.ltu.ibsalib.ImageQualityTest.testImageQuality(Test.android.kt:34)
streetsofboston
01/20/2025, 3:16 PMIvan
01/20/2025, 3:17 PMandroid.util.Log.d
. I guess mockk
should do the jobstreetsofboston
01/20/2025, 3:18 PMstreetsofboston
01/20/2025, 3:20 PMIvan
01/20/2025, 3:21 PMRobolectric
but I actually have never used itstreetsofboston
01/20/2025, 3:26 PMIvan
01/20/2025, 4:03 PMinitLocal
), any clue?ephemient
01/22/2025, 5:06 AM@RunWith(RobolectricTestRunner::class)
? @Config
alone does nothing without the runnerIvan
01/22/2025, 8:39 AMlog.d
problem , however, I got a different problem, Cannot load library opencv_java4
I think this one is related to how .so and jni files are imported... the unit test don't seem to locate the right folders on initLocal()
Ivan
01/22/2025, 10:50 AMephemient
01/22/2025, 10:58 AMCannot load librarynative JNI libraries for Android will not work in unit tests, because they run on the host in a non-Android environment
Ivan
01/22/2025, 10:59 AMephemient
01/22/2025, 11:00 AMIvan
01/22/2025, 11:00 AMIvan
01/22/2025, 11:01 AMbirghtness(image: Mat)
and i know that for certain image it returns 123.4
... there's no way to test this in a CI? I'd like to do it to know if a modification broke the behaviour 🤔ephemient
01/22/2025, 11:02 AMephemient
01/22/2025, 11:03 AMIvan
01/22/2025, 11:04 AMephemient
01/22/2025, 11:04 AMIvan
01/22/2025, 11:04 AMyou could use robolectric shadows to bypass the whole opencv class, but I'm not sure what you're trying to testExactly, i would like to call the real openvc functions
Ivan
01/22/2025, 11:05 AMephemient
01/22/2025, 11:05 AMIvan
01/22/2025, 11:07 AMIvan
01/22/2025, 11:10 AM./gradlew :composeApp:connectedAndroidTest
, is that what you mean with instrumented tests?ephemient
01/22/2025, 11:11 AMIvan
01/22/2025, 11:12 AMstreetsofboston
01/22/2025, 12:42 PMIvan
01/22/2025, 2:04 PMMat
which i would like to use during testing and that would be quite hard to fakeephemient
01/22/2025, 6:48 PMif there is an opencv library for JVM with an API compatible to the opencv for Android library, you can try substituting the dependency in the unit test configurationI'm not familiar with the opencv ecosystem at all, but if it's a simple maven dependency, then you could try forcing Gradle to use a different dependency for the unit tests, e.g.
configurations.all {
if (name.endsWith("UnitTestRuntimeClasspath")) {
resolutionStrategy.dependencySubstitution {
substitute(module("opencv:opencv-android:1.0"))
.using(module("opencv:opencv-jvm:1.0"))
.because("host JVM compatibility")
}
}
}