https://kotlinlang.org logo
#compose
Title
# compose
m

mattinger

05/13/2022, 1:57 PM
I get that having @Preview functions alongside a composable in the same file is useful. However, how are people dealing with their code coverage numbers, and these preview functions will show up as entirely uncovered?
c

Csaba Szugyiczki

05/13/2022, 2:19 PM
Hopefully you can exclude them from such statistics by excluding every function which has the
@Preview
annotation on them. If that is not an option, usually you can exclude stuff based on their name. If you add the
Preview
suffix to all of your preview functions, you can write a general rule to exclude them all.
z

Zach Klippenstein (he/him) [MOD]

05/13/2022, 4:37 PM
Or by not worrying about problematic metrics like code coverage in the first place 😉
2
a

agrosner

05/13/2022, 6:50 PM
🙁 if only.
j

Joseph Hawkes-Cates

05/14/2022, 8:06 PM
I haven't used any code coverage tools for Kotlin yet, but for previous ones I've used for java you can add start and stop comments that the coverage tool will honor to ignore sections of code in the coverage numbers. I'm already adding region comments around my previews so I can collapse preview code sections in Android Studio so adding another comment line for code coverage exclusion wouldn't be too intrusive.
5 Views