runTestWithData

fun <T> runTestWithData(    testCases: Iterable<T>,     context: CoroutineContext = EmptyCoroutineContext,     timeout: Duration = 1.minutes,     retries: Int = 1,     afterEach: (TestExecutionResult<T>) -> Unit = {},     handleFailures: (List<TestFailure<T>>) -> Unit = ::defaultAggregatedError,     afterAll: () -> Unit = {},     test: suspend TestScope.(TestCase<T>) -> Unit): TestResult

Executes multiple test cases with retry capabilities and timeout control. Timeout is independent for each attempt in each test case.

Example usage:

@Test
fun dataDrivenTest() = runTestWithData(
    testCases = listOf("test1", "test2"),
    timeout = 10.seconds,
    retries = 2,
    afterEach = { (data, retry), error ->
        println("Test case $data attempt $retry ${if (error != null) "failed" else "succeeded"}")
    },
    afterAll = { println("All tests completed") },
    handleFailures = { failures ->
        failures.forEach { (cause, data) -> println("Test $data failed: $cause") }
    },
) { (data, retry) ->
    // test implementation
}

Report a problem

Return

TestResult representing the completion of all test cases.

Parameters

testCases

Data to be used in tests. Each element represents a separate test case.

context

Optional coroutine context for test execution. Defaults to EmptyCoroutineContext.

timeout

Maximum duration allowed for each test attempt. Defaults to 1 minute.

retries

Number of additional attempts after initial failure (0 means no retries).

afterEach

Called after each test case attempt, regardless of success or failure. Receives the test case and error (if any occurred).

handleFailures

Called after all tests finished if any failures occurred. Receives a list of all failed test cases with their last failure cause. By default, throws AssertionError with an aggregated error message.

afterAll

Runs after all tests finished, but before handleFailures.

test

Test execution block. Receives TestCase containing both test data and current retry number.