Each test can be configured with various parameters. After the test name, invoke the config function passing in the parameters you wish to set. The available parameters are:
invocations- The number of times to run this test. Useful if you have a non-deterministic test and you want to run that particular test a set number of times to see if it eventually fails. A test will only succeed if all invocations succeed. Defaults to 1.
threads- Allows the invocation of this test to be parallelized by setting the number of threads. Value must be less or equal of invocations value. Similarly, if you set invocations to a value equal to the number threads, then each invocation will have its own thread.
enabled- If set to
falsethen this test is disabled. Can be useful if a test needs to be temporarily ignored. You can also use this parameter with boolean expressions to run a test only under certain conditions.
enabledIf- A function which provides the same ability as
enabledbut is lazily evaluated when the test case is due for execution.
timeout- sets a timeout for this test. If the test has not finished in that time then the test fails. Useful for code that is non-deterministic and might not finish. Timeout is of type
kotlin.Durationwhich can be instantiated like
3.minutesand so on.
tags- a set of tags that can be used to group tests (see detailed description below).
listeners- register test listeners to run only on this test.
extensions- register extensions to run only on this test.
An example of setting config on a test:
You can also specify a default TestCaseConfig for all test cases of a Spec:
Overriding the defaultTestCaseConfig function:
Or via assignment to the defaultTestConfig val: