Rhino WIP: Unit/Regression Testing

More often than not we work on complex workflows when scripting in Rhino. While working on a code that is trying to wrap a complicated workflow, it is possible for changes to break previously coded expectations and behaviour. For this reason it is important to write tests for these cases. Whenever code is changed, tests can be executed to verify that expectations are still met and new code is behaving correctly.

In Rhino WIP, Script Editor now includes a Tests browser panel on the left side of the editor. Similar to Explorer panel, you can point the Tests panel to a directory containing scripts. Any script with file name matching the pattern test_* is considered a test. All other files are ignored and not shown in the panel. Directories of test scripts, are considered groups of tests and are shown as such in the Tests panel

Tests pass if they do not throw an exception. If they do, it is considered a failure and a message is shown

You can run individual or groups of tests using the blue Run Test button

When a test is executed, the result is visualized as a Green (pass) or Red (fail) icon on the test. Note that unlike the file explorer, the language icon is not used here since that is kind of irrelevant. The test now shows the execution time as well.

You can even include Grasshopper files as tests. They will Fail if any of the components throw Error messages. See the tooltip showing the error message currently. This will be improved.

You can use the buttons in the panel toolbar to run all the tests or clear the results:

Test Execution

  • Tests are executed synchronously and on the Rhino main (UI) thread. This is how Rhino commands and Script Editor work as well.
  • Currently changes made to active Rhino document affect the document that is currently open in your Rhino instance. If you need a specific or empty document, you should open or create that in the script.
  • There is no support for tests that are derived from a base class yet. You can code that up yourself as long as you make the call to the test in the script global scope.
  • You can run tests asynchronously by specifying # async: true in the script. This way Rhino UI stays active during testing. Note that script might be executed on an non-UI thread so plan for that accordingly.


As usual, I would love your testing and feedback. There is a list of tickets that I have already made and these are work in progress.

Testing Work-in-progress Tickets

2 Likes