Skip to content

DanielAbalde/Tenrec

Repository files navigation

Tenrec

Run Grasshopper files as Unit Tests in Visual Studio

This WIP plugin and workflow allows to replace unit tests written from code (as usual), by Grasshopper files, and to continue using the Test Explorer in Visual Studio. The plugin contains two special objects, a group that allows to gather components into a single unit test, and a component that throws an error when the test fails.

Capture Tenrec Group

🗺️ Motivation

The motivation is to automate the test code and allow to create Grasshopper definitions that can be both component unit tests and integration tests between various components. It also allows to have a better control over the data, mainly geometrical, that parameterise the tests. And above all, it avoids having to open Rhino + Grasshopper + Document to debug a plugin.

😎 Overview

The idea is to create test definitions in Grasshopper and use the Tenrec Source Code Generator to create a code file with all the classes and methods contained in the definition, and add this to your test project in Visual Studio. Then you run the tests and don't need to debug your plugin by opening Rhino and Grasshopper.

🔒 Limitations

It only works for Rhino 7 or higher (it uses RhinoInside), with .NET Framework 4.8 or higher and the project must be build to x64. For the moment the Unit Test Source Code Generator is just for Windows and just generate C# code using the MSTest framework.

📖 How to use it

Install Tenrec.gha
  1. Download last release from https://github.com/DanielAbalde/Tenrec/releases.
  2. Paste Tenrec.gha in C:\Users<YOUR USERNAME>\AppData\Roaming\Grasshopper\Libraries.
  3. Restart Rhinoceros and Grasshopper.
  4. Find Tenrec group and Assert component in Params > Util.
Create a Grasshopper Unit Test file
  1. Create a Grasshopper definition to make a Unit Test.
  2. Add the Assert component, set input Assert (A) to false when your Unit Test fail (and true otherwise) and include a message for when that happens.
  3. Select all components that are part of the Unit Test.
  4. Add a Tenrec group to the canvas, it will group all selected components.
  5. Change the Tenrec group name by double click on it.
  6. Repeat 1 to 5 if you want to include more Unit Test in the same file.
  7. Save the Grasshopper file in your test folder.
  8. In the top right corner, click on settings > Source Code Generator.
  9. The Unit Test Source Code Generator window should appear, set your test folder path in the Grashopper file folder section, set the folder to save the code file in Output folder section and its name in Output name.
  10. Press Generate and close the window. The code file will be located at Output folder/Output name.cs
Create a Unit Test Project
  1. In Visual Studio 2019, create a new Unit Test Project (.NET Framework). with .NET Framework 4.8.
  2. From project Properties > Build, set Platform target: x64 and make sure Prefer 32 bit is disabled/unchecked.
  3. Browse in Nuget Package Manager to install the last realease of Rhino.Inside.
  4. If in the project references you see several Rhino libraries, set copy local to false to all of them except Rhino.Inside (Eto, Eto.Wpf, GH_IO, Grasshopper, Rhino.UI, RhinoCommon, RhinoWindows). If you see a single Rhino.Inside nuget package, ignore this step.
  5. Add reference to Tenrec.dll provided in the download.
  6. In your project from Solution Explorer, Add > Existing item... and include the code file generated previosly.
  7. Build the project.
Run the Unit Tests
  1. In Visual Studio 2019 toolbar > Test > Test Explorer.
  2. Press Run All Test In View.
  3. You should see the results in all your Grasshopper tests.

🌈 License

This project is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

❓ Questions & Feedback

Join to my Discord for assitance or feedback.

☕ Support me!

Contribute to thank or further develop using Ko-fi or Paypal. Thank you!

About

Unit Tests and Integration Tests using Grasshopper files

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Languages