runTestWithData
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
}
Return
TestResult representing the completion of all test cases.
Parameters
Data to be used in tests. Each element represents a separate test case.
Optional coroutine context for test execution. Defaults to EmptyCoroutineContext.
Maximum duration allowed for each test attempt. Defaults to 1 minute.
Number of additional attempts after initial failure (0
means no retries).
Called after each test case attempt, regardless of success or failure. Receives the test case and error (if any occurred).
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.
Runs after all tests finished, but before handleFailures.
Test execution block. Receives TestCase containing both test data and current retry number.