log

suspend fun <T> TestDsl.log(value: T): T(source)

Logs a value in the test output.

Example

test("My test") {
val testUser = log(createTestUser())
// …
}
» Logged ‘User(username=Bob, …)’

This function is especially useful if you use Power Assert, as it allows displaying intermediary values of a complex expression.

To enable Power Assert, follow these steps then add:

powerAssert {
functions = listOf(
// …Add any other function you want to instrument…
"opensavvy.prepared.suite.assertions.log",
)
}

Then, in your tests:

test("My test") {
log(12 + 5)
}
» Logged ‘17’
log(12 + 5)
|
17

You can use this function to get more context about complex expressions when a test fails.


suspend fun <T> TestDsl.log(value: T, additionalInfo: () -> String): T(source)

Logs a value in the test output, with some additionalInfo.

Example

test("My test") {
val testUser = log(createTestUser()) { "Created test user" }
// …
}
» Logged ‘User(username=Bob, …)’
Created test user

This function is especially useful if you use Power Assert, as it allows displaying intermediary values of a complex expression.

To enable Power Assert, follow these steps then add:

powerAssert {
functions = listOf(
// …Add any other function you want to instrument…
"opensavvy.prepared.suite.assertions.log",
)
}

Then, in your tests:

test("My test") {
log(12 + 5) { "Important intermediary result" }
}
» Logged ‘17’
Important intermediary result
log(12 + 5)
|
17

You can use this function to get more context about complex expressions when a test fails.

Parameters

additionalInfo

A lambda that generates a String that will be printed alongside the message.