https://kotlinlang.org logo
#konsist
Title
# konsist
d

David

09/29/2023, 8:10 AM
Thanks for the great tool, it is extremely powerful! Thought I'd share some sweet Compose Preview tests that I found useful:
Copy code
class ComposePreviewTests {
    @Test
    fun ensureAllPreviewsArePrivate() {
        allPreviewFunctions().assert {
            it.hasPrivateModifier
        }
    }

    @Test
    fun ensureAllPreviewsStartWithPrefixPreview() {
        allPreviewFunctions().assert {
            it.name.startsWith("Preview")
        }
    }

    private fun allPreviewFunctions() = Konsist.scopeFromProject().functions().withAllAnnotations("Preview")
}
❤️ 2
i

igor.wojda

09/29/2023, 4:33 PM
Thx for the feedback and inspiration 🙏 I will add samples to the Android Snippets. BTW you can use
.withAnnotationOf(Preview::class)
to check by type rather than string.
d

David

09/29/2023, 5:38 PM
Ah nice, thanks for the improvement 🙏
Regarding the android snippets, seems like they are not publicly accessible? Is this the intention?
2 Views