Sometimes your code might use some functionalities straight from the JVM, which are very hard to simulate. With Kotest System Extensions, these difficulties are made easy to mock and simulate, and your code can be tested correctly. After changing the system and using the extensions, the previous state will be restored.
This code is sensitive to concurrency. Due to the JVM specification there can only be one instance of these extensions running (For example: Only one Environment map must exist). If you try to run more than one instance at a time, the result is unknown.
With System Environment Extension you can simulate how the System Environment is behaving. That is, what you're obtaining from
Kotest provides some extension functions that provides a System Environment in a specific scope:
You can also use multiple values in this extension, through a map or list of pairs.
These functions will add the keys and values if they're not currently present in the environment, and will override them if they are. Any keys untouched by the function will remain in the environment, and won't be messed with.
Instead of extensions functions, you can also use the provided Listeners to apply these functionalities in a bigger scope. There's an alternative for the Spec/Per test level, and an alternative for the Project Level.
In the same fashion as the Environment Extensions, you can override the System Properties (
And with similar Listeners:
Similarly, with System Security Manager you can override the System Security Manager (
And the Listeners:
Sometimes you want to test that your code calls
System.exit. For that you can use the
System Exit Listeners. The Listener will throw an exception when the
System.exit is called, allowing you to catch it and verify:
Maybe you want to guarantee that you didn't leave any debug messages around, or that you're always using a Logger in your logging.
For that, Kotest provides you with
NoSystemErrListener. These listeners won't allow any messages to be printed straight to
Some codes use and/or are sensitive to the default Locale and default Timezone. Instead of manipulating the system defaults no your own, let Kotest do it for you!
And with the listeners