Is it possible add custom error message when tests...
# konsist
s
Is it possible add custom error message when tests are failed ?
i
Currently not - error message is derived from test name ATM. Please present a concrete example where this could be helpfull - tell me what you see now and what exactly you would like to be displayed?
s
@igor.wojda
Copy code
@Test
fun `no Composable function should use 'Preview' annotation`() {
    Konsist
        .scopeFromProduction("app")
        .files
        .assertNot {
            it.containsFunction { function ->
                function.hasAnnotationOf<Preview>()
            }
        }
}
Suppose on test fail we will get the error something like below :
Assert 'no Composable function should use 'Preview' annotation' has failed. Invalid files (1):
/Users/swapnilmusale/StudioProjects/XXX/app/src/main/java/com/devx/XXX/ui/home/HomeScreen.kt (HomeScreen FileDeclaration)
Here I wanted to provide more info on test fail case :- Please use
@ThemedPreview
annotation instead of
@Preview
annotation. Also don't want to include all these info in test name which can be get expanded to more lengthy. Hope you will consider this case as valid and provide a way to accomplish the same.
i
Sounds reasonable I am thinking about
Copy code
.assertNot("Custom message") {
    ...
}
Any thoughts?
s
Yea looks good to me
🙂 1
i
I will try to include this in the next release
Now
Copy code
Assert 'no Composable function should use 'Preview' annotation' has failed. Invalid files (1):
/Users/swapnilmusale/StudioProjects/XXX/app/src/main/java/com/devx/XXX/ui/home/HomeScreen.kt (HomeScreen FileDeclaration)
Proposal
Copy code
Assert 'no Composable function should use 'Preview' annotation' has failed. 
CUSTOM ASSERT MESSAGE
Invalid files (1):
/Users/swapnilmusale/StudioProjects/XXX/app/src/main/java/com/devx/XXX/ui/home/HomeScreen.kt (HomeScreen FileDeclaration)
s
Great ...
i
PR was merged - this feature will be part of the next version. Release is targeted for latter this week https://github.com/LemonAppDev/konsist/pull/495
❤️ 1