Hi :slightly_smiling_face: I saw your presentation...
# konsist
r
Hi 🙂 I saw your presentation on KotlinConf24 in Copenhagen and have since then been pushing for the integration of Konsist into our unit test step on the pipeline at work and we have finally integrated Konsist tests into our Pipeline! I have a question. If I have an object with some variables (a class) and I want to assert on a value of these variables, can that be done? Simple sample below
Copy code
data class Feature(val name: String, val enabled: Boolean)

object Features{
   val featureOne = Feature(name = "FeatureOne", enabled = false)
   val featureTwo = Feature(name = "FeatureTwo, enabled = true)
}
So I want to assert that
enabled
for Feature class declarations is false
❤️ 1
p
I think in this case only a text comparision is possible:
Copy code
val propertyRegex = Regex("enabled\\s*=\\s*true")
        Konsist.scopeFromProduction()
            .objects()
            .withName("Features")
            .properties()
            //.withTypeOf(Feature::class)
            .assertTrue {
               it.value == null || !propertyRegex.containsMatchIn(it.value!!)
            }
The
withTypeOf
- filter is only working when using explicit type declaration. This kind of test is not very stable. because changing the interna of the
Feature
class possibly makes an update of the test necessary.
👍 1
i
@Rasmus Larsen "Great to see you're using Konsist! 😊 Quick note: Konsist API currently focuses on high-level declarations. For detailed analysis of function bodies or values, you can use the
text
property (
value
is better here) for string comparisons if needed.
1