You test Swift methods that have prerequisites by only testing behavior with inputs that match these prerequisites. The behavior when the precondition is not met becomes clear without further testing, since the preconditions are baked into the standard library.
If you doubt that you have correctly set the precondition, you can output the precondition expression to a logical function, and then check that for the correct recognition of valid values ββwith invalid inputs.
However, you can create for yourself what you want here:
The option of throwing exceptions for failures with a precondition / statement would do the trick: one would include it in debug builds and disable it in release builds.
Instead of calling Apple precondition you can write your own function, say require . This can be conditionally compiled to act according to your desire. Then you would use it wherever you use precondition .
source share