Everything Is A Factory
In @fluentfixture, factories are the smallest unit of the data generators. From simple numbers to a massive amount of complex data, it's all generated by a collection of factories. The core design of the library relies on the following three principles:
Immutability
Reusability
Fail-fast
Immutability
Everything is immutable. The behavior of a factory cannot be modified after the instance is created. The only way to introduce new behaviors is to decorate factories with other factories. This behavior is crucial for reusability and eliminating side effects.
In the example above, there is no way to change the lower bound and the upper bound of the integer variable.
Reusability
Because of the immutability approach, all factories are reusable.
In the example above, integerPlusHalf1
and integerPlusHalf2
are identical. Without immutability, we cannot predict the output because every modification on the integer
variable affects the output.
Fail-fast
Factories check the types and values of the given parameters during the initialization step.
In the example above, a parameter exception occurs during the initialization. Therefore, the last line will never be executed.
Last updated