A library to help auto-generate screenshot tests from Composable Previews with any screenshot testing library: JVM-based (i.e. Paparazzi, Roborazzi) as well as Instrumentation-based (i.e. Shot, Dropshots, Android-Testify, etc.)
MIT License
121
stars
1
forks
source link
Optimization suggestion for reducing test initialization time with ParameterizedRobolectricTestRunner #13
Thanks as always!
I've been using the ComposablePreviewScanner library and noticed that each test takes approximately 1-5 seconds, which significantly increases the total test duration. It seems that ParameterizedRobolectricTestRunner.Parameters is invoked for each test. I found that using a lazy initialization for the previews can optimize performance. Here's a snippet that could potentially be included in the README:
companion object {
private val previewsCache: List<ComposablePreview<AndroidPreviewInfo>> by lazy {
val (value, time) = measureTimedValue {
AndroidComposablePreviewScanner()
.scanPackageTrees("your.package")
.getPreviews()
}
println("Compose Preview Scanning took $time")
value
}
@JvmStatic
@ParameterizedRobolectricTestRunner.Parameters
fun values(): List<ComposablePreview<AndroidPreviewInfo>> {
return previewsCache
}
}
Would it be possible to consider this approach for inclusion in the documentation to help others improve the performance of their tests?
Thanks as always! I've been using the ComposablePreviewScanner library and noticed that each test takes approximately 1-5 seconds, which significantly increases the total test duration. It seems that ParameterizedRobolectricTestRunner.Parameters is invoked for each test. I found that using a lazy initialization for the previews can optimize performance. Here's a snippet that could potentially be included in the README:
Would it be possible to consider this approach for inclusion in the documentation to help others improve the performance of their tests?