Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Create a palette with tools for creating unit tests
ResourceFunction["OpenTestWritingPalette"][] creates a palette with buttons that allow you to create VerificationTest expressions from pairs of input-output cells. | |
ResourceFunction["OpenTestWritingPalette"][fun] uses fun[] to create a TestID for each test that is created. | |
Open the palette:
In[1]:= |
Out[1]= |
The palette has a number of buttons:
The buttons under the heading "Creating tests" all do similar things: they generate tests from input-output cell groups. Evaluate some input to test and then select theCellGroup (or multiple cell groups) that holds the input and output. Then press Create tests to create a VerificationTest (or multiple) that can be run immediately:
In[2]:= |
Out[2]= |
In[3]:= |
Out[3]= |
If you use the Browse… button, you can select a plain-text output file to directly append new tests to with the "Add tests to file" button.
Generated messages will be added to the test as well:
In[4]:= |
Out[4]= |
In[5]:= |
Out[5]= |
You can define your own method for generating a TestID for each test:
In[6]:= |
In[7]:= |
Out[7]= |
In[8]:= |
Out[8]= |
Use None if you don't want to automatically generate test IDs:
In[9]:= |
In[10]:= |
Out[10]= |
In[11]:= |
Out[11]= |
You can also convert tests in a testing notebook. Open the example notebook, highlight tests and use the Copy tests button:
In[12]:= |
Out[12]= |
Paste them:
Create tests with a different SameTest:
In[13]:= |
Out[13]= |
Create a test:
In[14]:= |
Out[14]= |
In[15]:= |
Out[15]= |
You can change the SameTestby clicking the Set button on the palette and entering a new one in the dialog:
A Tooltip on the SameTest text will show the test currently being used:
Create a new test:
In[16]:= |
Out[16]= |
Pressing Reset button on the palette will revert the test back to the original value (which is Equal in this case since that was the option value the palette was created with):
If you have a custom test function assigned to a variable, wrap it in Hold to prevent it from evaluating before being inserted into the test:
In[17]:= |
Out[18]= |
In[19]:= |
Out[19]= |
Create a test:
In[20]:= |
Out[20]= |
In[21]:= |
Out[21]= |
Create tests with time constraints:
In[22]:= |
Out[22]= |
In[23]:= |
Out[24]= |
In[25]:= |
Out[25]= |
Create tests with memory constraints:
In[26]:= |
Out[26]= |
In[27]:= |
Out[27]= |
In[28]:= |
Out[28]= |
Create a TestID generator that automatically increments with each new test:
In[29]:= |
Create some tests:
In[30]:= |
Out[30]= |
In[31]:= |
Out[31]= |
This work is licensed under a Creative Commons Attribution 4.0 International License