SharedProvider¶
class SharedProvider<T>
A Shared is a lazily-created value that is reused between tests.
Most of the time,
PreparedProvidershould be preferred to this class. To learn why, seeShared.
Although SharedProvider is conceptually equivalent to PreparedProvider, and can be used to generate multiple Shared instances from the same block in exactly the same way, this is not recommended.
Shared values should only be used when all of these are true:
-
The generated value is immutable,
-
The generated value is too expensive to compute each test,
-
The generation of this value does not involve side effects which may change the output of a test.
If these conditions are met, then generating multiple values from the same SharedProvider makes no sense, as it will necessarily return the same value.
This class exists because of its other use-case: capturing the name of the property it is instantiated to, using the by keyword. See shared and provideDelegate.
Functions¶
named¶
Deprecated¶
The primary use-case for this method is to generate multiple shared values from a single provider. This implies you are relying on side effects in the shared value generation. This is not recommended. See the documentation of Shared and SharedProvider to learn more.
Provides a Shared value instance bound to the given name.
This is not recommended, because it likely means you are relying on side effects. See Shared and SharedProvider for an explanation.
provideDelegate¶
operator fun provideDelegate(thisRef: Any?, property: KProperty<*>): SharedDelegate<T>