X - Type of exception that can be thrown by the runnable objectpublic static interface FlakyTestRunner.Builder<X extends Throwable>
A flaky test runner is used to handle test cases that might fail intermittently. The builder allows for configuring various aspects of the runner such as the maximum number of iterations before failure, the delay between iterations, garbage collection between iterations, and custom loggers for informational and error messages.
Example usage:
Builder<Exception> builder = FlakyTestRunner.builder(action);
builder.withMaxIterations(3)
.withIterationDelay(1000)
.withInfoLogger(myInfoLogger)
.withErrorLogger(myErrorLogger)
.build()
.runOrThrow();
FlakyTestRunner,
FlakyTestRunner.RunnableThrows| Modifier and Type | Method and Description |
|---|---|
FlakyTestRunner.RunnableThrows<X> |
build()
Constructs a runnable object that encapsulates the configured flaky test behavior.
|
FlakyTestRunner.Builder<X> |
withErrorLogger(Consumer<? super String> errorLogger)
Sets the error logger to use for error messages.
|
FlakyTestRunner.Builder<X> |
withFlakyOnThisArchitecture(boolean flakyOnThisArchitecture)
Configures whether the runner is considered flaky on the current architecture.
|
FlakyTestRunner.Builder<X> |
withInfoLogger(Consumer<? super String> infoLogger)
Sets the info logger to use for informational messages.
|
FlakyTestRunner.Builder<X> |
withInterIterationGc(boolean interIterationGc)
Sets if a garbage collection should be requested between each iteration.
|
FlakyTestRunner.Builder<X> |
withIterationDelay(long delayMs)
Sets the delay between each iteration in milliseconds.
|
FlakyTestRunner.Builder<X> |
withMaxIterations(int maxIterations)
Sets the maximum number of iterations before the runner fails.
|
FlakyTestRunner.Builder<X> withFlakyOnThisArchitecture(boolean flakyOnThisArchitecture)
Default value: true
flakyOnThisArchitecture - Flag indicating flakinessFlakyTestRunner.Builder<X> withMaxIterations(int maxIterations)
This setting allows configuring how many times the runner will attempt the test before failing.
Default value: 2
maxIterations - non-negative value to useFlakyTestRunner.Builder<X> withIterationDelay(long delayMs)
This sets the time delay between retries if the test is failing.
Default value: 500 ms
delayMs - non-negative value to useFlakyTestRunner.Builder<X> withInterIterationGc(boolean interIterationGc)
Enabling this setting can help to clean up resources between test attempts.
Default value: true
interIterationGc - flag to enable or disable garbage collection between iterationsFlakyTestRunner.Builder<X> withInfoLogger(Consumer<? super String> infoLogger)
Default value: System.out::println
infoLogger - Logger to use for informational messagesFlakyTestRunner.Builder<X> withErrorLogger(Consumer<? super String> errorLogger)
Default value: System.err::println
errorLogger - Logger to use for error messagesFlakyTestRunner.RunnableThrows<X> build()
This method finalizes the builder and constructs a new runnable object to handle the flaky test behavior based on the configured settings.
This method can only be called once per builder instance.
Copyright © 2023. All rights reserved.