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 TestCreate expressions from pairs of input-output cells. | |
ResourceFunction["OpenTestWritingPalette"][fun] uses fun to create a TestID for each test that is created. | |
SameTest | Inherited | SameTest option for generated tests |
TimeConstraint | Inherited | TimeConstraint option for generated tests |
MemoryConstraint | Inherited | MemoryConstraint option for generated tests |
MetaInformation | Inherited | MetaInformation option for generated tests |
"TestHead" | TestCreate | type of test generated |
"TestFile" | None | file to append tests to |
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 an input to test and then select the CellGroup (or multiple cell groups) that holds the input and output. Then click Create tests to create one or more TestCreate expressions:
In[2]:= |
Out[2]= |
In[3]:= |
Out[3]= |
Run the test:
In[4]:= |
Out[4]= |
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[5]:= |
Out[5]= |
In[6]:= |
Out[6]= |
In[7]:= |
Out[7]= |
You can define your own method for generating a TestID for each test:
In[8]:= |
In[9]:= |
Out[9]= |
In[10]:= |
Out[10]= |
Use None if you don't want to automatically generate test IDs:
In[11]:= |
In[12]:= |
Out[12]= |
You can also convert tests in a testing notebook. Open the example notebook, highlight tests and use the Copy tests button:
In[13]:= |
Out[13]= |
Paste them:
Create tests with a different SameTest:
In[14]:= |
Out[14]= |
Create a test:
In[15]:= |
Out[15]= |
In[16]:= |
Out[16]= |
In[17]:= |
Out[17]= |
You can change the SameTest by 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[18]:= |
Out[18]= |
In[19]:= |
Out[19]= |
In[20]:= |
Out[20]= |
Clicking the 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[21]:= |
Out[22]= |
Create a test:
In[23]:= |
Out[23]= |
In[24]:= |
Out[24]= |
In[25]:= |
Out[25]= |
If you use the Set button in the palette to change the SameTest to myTest, you don't need to wrap it in Hold.
Create tests with time constraints:
In[26]:= |
Out[26]= |
In[27]:= |
Out[28]= |
In[29]:= |
Out[29]= |
In[30]:= |
Out[30]= |
Create tests with memory constraints:
In[31]:= |
Out[31]= |
In[32]:= |
Out[32]= |
In[33]:= |
Out[33]= |
In[34]:= |
Out[34]= |
Change the type of test generated by the tool:
In[35]:= |
Out[35]= |
In[36]:= |
Out[36]= |
Create a TestID generator that automatically increments with each new test:
In[37]:= |
Create some tests:
In[38]:= |
Out[38]= |
In[39]:= |
Out[39]= |
Wolfram Language 13.0 (December 2021) or above
This work is licensed under a Creative Commons Attribution 4.0 International License