testValues

open fun testValues(): List<Value>

Returns a list of representative values for this field to be used in automated testing.

This method provides edge cases and boundary values that are useful for property-based testing and visual regression testing (VRT). The returned values are used as test inputs to ensure the preview component behaves correctly across different states.

Default behavior

By default, this method returns a list containing only the initialValue. Built-in field types override this to provide meaningful edge cases:

Usage in property-based testing

The test values are typically used as edge cases in property-based testing frameworks:

@Test
fun `component handles all field values`() = runDesktopComposeUiTest {
val state = PreviewLabState()
setContent { TestPreviewLab(state) { MyPreview() } }

val myField by state.field<String>("label")

// Use testValues as edge cases for property-based testing
forAll(Arb.string().plusEdgecases(myField.testValues())) { value ->
myField.value = value
awaitIdle()
// assertions...
true
}
}

Custom implementation

Override this method when creating a custom field to provide meaningful edge cases:

class PercentageField(label: String, initialValue: Int) :
MutablePreviewLabField<Int>(label, initialValue) {

override fun testValues(): List<Int> = listOf(0, 50, 100, initialValue)

@Composable
override fun Content() { /* ... */}
}

Using withTestValues

For existing fields, use me.tbsten.compose.preview.lab.field.withTestValues to add additional test values without creating a new class:

val fontSize = fieldValue {
IntField(label = "Font Size", initialValue = 14)
.withTestValues(8, 12, 24, 48) // Add edge cases
}

Return

A list of values to use as test inputs, including edge cases and boundary values

See also