Android Test Snippets
Konsist can be used to guard the consistency of the Android project.
1. Classes Extending ViewModel Should Have ViewModel Suffix
@Test
fun `classes extending 'ViewModel' should have 'ViewModel' suffix`() {
Konsist
.scopeFromProject()
.classes()
.withParentClassOf(ViewModel::class)
.assertTrue { it.name.endsWith("ViewModel") }
}2. Every ViewModel Public Property Has Flow Type
@Test
fun `Every 'ViewModel' public property has 'Flow' type`() {
Konsist
.scopeFromProject()
.classes()
.withParentClassOf(ViewModel::class)
.properties()
.withPublicOrDefaultModifier()
.assertTrue {
it.hasType { type -> type.bareSourceType == "Flow" }
}
}3. Every ViewModel StateFlow Property Has Explicit Backing Field
4. Repository Classes Should Reside In repository Package
5. No Class Should Use Android Util Logging
6. All Jetpack Compose Previews Contain Preview In Method Name
7. Every Class With Serializable Must Have Its Properties Serializable
Last updated