Wolfram Language Paclet Repository
Community-contributed installable additions to the Wolfram Language
Utilities for locally overriding function behavior, useful in software testing and much more
Contributed by: Jesse Friedman
To install this paclet in your Wolfram Language environment,
evaluate this code:
PacletInstall["Wolfram/Mockingbird"]
To load the code after installation, evaluate this code:
Needs["Wolfram`Mockingbird`"]
Evaluate an expression using a mocked version of the function f:
| In[1]:= | ![]() |
| Out[1]= |
Use MockDefinitionGroup to specify multiple, potentially interconnected definitions:
| In[2]:= | ![]() |
| Out[3]= |
By default, MockDefinition shields against recursive invocation, so a mock definition for a function can call the same function's original definition without danger of infinite recursion:
| In[4]:= |
| Out[5]= |
| In[6]:= | ![]() |
| Out[6]= |
Create a mocked version of URLExecute for testing the UKPostcodeLookup resource function. The mock definition validates the URL in an HTTP request and returns a canned response without actually making the request:
| In[7]:= | ![]() |
This mocked version can be used to validate the request-construction and response-parsing logic in the function under test without the expense of making live HTTP requests:
| In[8]:= | ![]() |
| Out[9]= |
| In[10]:= |
| Out[10]= | ![]() |
The use of ConfirmBy in the mock definition causes the evaluation to exit early and return a Failure object if the requested URL is incorrect:
| In[11]:= | ![]() |
| Out[11]= |
| In[12]:= |
| Out[12]= |