# Rhino.Testing

**URL:** <https://discourse.mcneel.com/t/rhino-testing/192259>\
**Category:** Rhino Developer\
**Tags:** windows, testing, unit-testing, rhinotesting\
**Created:** [October 2, 2024, 3:10pm UTC](https://discourse.mcneel.com/t/rhino-testing/192259 "2024-10-02T15:10:32Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![janotaondrej91](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/janotaondrej91/32/504618_2.png) [@janotaondrej91](https://discourse.mcneel.com/u/janotaondrej91)\
**Post date:** [October 2, 2024, 3:10pm UTC](https://discourse.mcneel.com/t/rhino-testing/192259/1 "2024-10-02T15:10:32Z")

</div>

Hello dear colleagues,

I have recently came to conclusion that I need to do a unit tests to my GH plugin. Searching this forum I have discovered few repos/packages which should be suitable for this.

First idea was to test my GH scripts with C# custom components according to this [sample](https://github.com/mcneel/rhino-developer-samples/tree/7/rhino.inside/dotnet/SampleUnitTests/GrasshopperTests). However, it did not worked well and I left that approach. Issues are described in here ([1](https://discourse.mcneel.com/t/problem-with-unit-testing-of-gh-components-using-xunit-and-rhino-inside/155042) and [2](https://discourse.mcneel.com/t/grasshopper-and-unit-tests-with-xunit/190325/3) ).

Finally, I have found [Rhino.Testing](https://discourse.mcneel.com/t/automated-testing-with-rhino/188930) library which looks very promising. There are also the [SampleTests](https://github.com/mcneel/SimpleRhinoTests) repo, which I downloaded. My aim now is to test my plugin in the following cases:

- Test my methods which uses RhinoCommon library.
- Read Geometry from Rhino and use it for test of my methods.
- Call methods like Curve.CreateInterpolatedCurve() in my tests and use result for testing my methods.
- Run GH script and read result according to [Rhino.Testing](https://discourse.mcneel.com/t/automated-testing-with-rhino/188930) workflow.

And here comes the issues. Over last two days I have tried to put Rhino.Testing library into operation unfortunately behavior of the test is unclear to me.

When I run the sample repo it works except tests when Rhino is opened (Headless or not; Net7.0 version works correctly). In these cases test are simply aborted, testing ends without any result. Test where Rhino.FileIO is used works just fine.

When I add new project to my plugin and set things according to instruction written [here.](https://github.com/mcneel/Rhino.Testing) it works only if I don’t use SetupFixture class.  
So I can use Rhinocommon classes like Point3d etc. but I cannot use advanced methods like intersections and others. If I use them in test method I get error that _rhcommon\_c.dll_ cannot be referenced/found.

Using SetupFixture (according to the sample file and readme in the Rhino.Testing), which should solve this problem, as Rhino must be initialized for these advanced methods, leads to  
different error. It occurs when _OneTimeSetUp_ method is called. I have tried to reference RhinoCommon.dll for both Rhino 7 and Rhino 8 version. No change at all.

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/9/9/1/9913e8a759808837aded2edbde13f7645d9736bc.png)

Class for the test is quite simple:

```auto
[TestFixture]
 public sealed class TestTunnel : RhinoTestFixture
 {
  [Test, Description("Test that constructor produce valid TBM_Class")]
     public void TestTunnelConstructor()
     {
         Assert.That(true);
     }
 }

```

Last try which I have done is simply adding [SampleTests](https://github.com/mcneel/SimpleRhinoTests) project to my solution. That works (again except tests where Rhino does not use _Rhino.FileIO_ to read .3dm file). It works even if I reference different version of _RhinoCommon.dll_ assembly in the tests project and my plugin. However, if I manually remove _RhinoCommon.dll_ assembly reference from unit test project and add new one at the same location it stops to work and produce following error _(System.DllNotFoundException: Liberary DLL RhinoLibraryCannot be found)_:

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/9/f/e/9fe5c7ff566690326a14208d1088ac4125c706df.png)

So my question is what I am missing/doing wrong? Why it works when I add sample repo but not for new one? What directory is not found? Why openHeadless method does not work for .Net48 version and work for .Net7.0?

Hope @fraguada or @menno could help me.

Thanks for the reply and time

Best regasrds

Ondřej

---

<div class="post-metadata">

**Author:** ![janotaondrej91](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/janotaondrej91/32/504618_2.png) [@janotaondrej91](https://discourse.mcneel.com/u/janotaondrej91)\
**Post date:** [October 3, 2024, 11:18am UTC](https://discourse.mcneel.com/t/rhino-testing/192259/2 "2024-10-03T11:18:31Z")

</div>

Just my own update. I was able to resolve problem with missing RhinoLibrary

> [@janotaondrej91](#):
>
> Using SetupFixture (according to the sample file and readme in the Rhino.Testing), which should solve this problem, as Rhino must be initialized for these advanced methods, leads to  
> different error. It occurs when _OneTimeSetUp_ method is called. I have tried to reference RhinoCommon.dll for both Rhino 7 and Rhino 8 version. No change at all.
> 
> ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/9/9/1/9913e8a759808837aded2edbde13f7645d9736bc.png)

and DirectoryNotFoundException.

> [@janotaondrej91](#):
>
> Last try which I have done is simply adding [SampleTests](https://github.com/mcneel/SimpleRhinoTests) project to my solution. That works (again except tests where Rhino does not use _Rhino.FileIO_ to read .3dm file). It works even if I reference different version of _RhinoCommon.dll_ assembly in the tests project and my plugin. However, if I manually remove _RhinoCommon.dll_ assembly reference from unit test project and add new one at the same location it stops to work and produce following error _(System.DllNotFoundException: Liberary DLL RhinoLibraryCannot be found)_:
> 
> ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/9/f/e/9fe5c7ff566690326a14208d1088ac4125c706df.png)

I have mismatched copy local for some .dll and configs.xml file.

Now I have run into another (but minor issue). Which can be rather feature then problem. I would like to perform multiple testcases on one test. Some of the input to the tests is Rhino Geometry (curves, points etc). However, if I use TestCaseSource or TestCase attribute and define geometry in that input i again fails and raise error that RhinoCommon cannot be loaded.

```auto
    [TestFixture]
    public sealed class TestTunnel : RhinoTestFixture
    {
        private static IEnumerable<TestCaseData> TestTunnelConstructor_Params()
        {
            yield return new TestCaseData(null, null, Point3d.Unset, Point3d.Unset, false);
            yield return new TestCaseData(null, null, Point3d.Unset, Point3d.Unset, false);
            yield return new TestCaseData(null, null, new Point3d(0, 0, 0), Point3d.Unset, false);
            yield return new TestCaseData(null, null, new Point3d(0, 0, 0), new Point3d(1, 1, 1), false);
            yield return new TestCaseData(Curve.CreateInterpolatedCurve(new List<Point3d>() { new Point3d(0, 0, 0), new Point3d(1, 0, 0) }, 1), new List<Curve>(), new Point3d(0, 0, 0), new Point3d(1, 0, 0), true);
            yield return new TestCaseData(Curve.CreateInterpolatedCurve(new List<Point3d>() { new Point3d(0, 0, 0), new Point3d(1, 0, 0) }, 1), new List<Curve>(), new Point3d(0, 0, 0), new Point3d(1, 0, 0), true);
        }
        [Test, Description("Test of constructor produce valid TBM_Class")]
        [TestCaseSource(nameof(TestTunnelConstructor_Params))]
      
        public void TestTunnelConstructor(Curve alignment, List<Curve> alignments, Point3d startPoint, Point3d endPoint, bool result)
        {
            var tunnel = new TBM.TBM_Common.TBM_Tunnel(null, null, startPoint, endPoint);
            Assert.That(tunnel.IsValid == result);
        }

    }

```

If geometry is created directly in the test method it works. I except problem to be in the SetupFixuture class which (i assume) is not called before the input values (together with rhino geometry) are initialized. I am I right? Is this bug or feature I have to live with it? I can image some workaround (reading geometry from .3dm etc). But direct input with TestCaseSource would be much easier.

Thanks a lot for your reply and time.

Ondřej

---

<div class="post-metadata">

**Author:** ![CallumSykes](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/callumsykes/32/569341_2.png) [@CallumSykes](https://discourse.mcneel.com/u/CallumSykes)\
**Post date:** [October 3, 2024, 7:53pm UTC](https://discourse.mcneel.com/t/rhino-testing/192259/3 "2024-10-03T19:53:50Z")

</div>

I’ve followed along with this thread, and it sounds like things are mostly working for you now?

Regarding this;

> [@janotaondrej91](#):
>
> Some of the input to the tests is Rhino Geometry (curves, points etc). However, if I use TestCaseSource or TestCase attribute and define geometry in that input i again fails and raise error that RhinoCommon cannot be loaded.

The Rhino.Testing library inserts a resolver into the test classes that tell dotnet “Hey, if you can’t find an assembly, ask me! I might know where it is!”. Unfortunately, static C# properties load _before_ this resolver is registered. Hence, it’s best if you use the `[RhinoTestFixture]` instead of inheriting the Test Setup class as attributes are created before static properties, and hence, allow that resolver to be registered before the static class can be instantiated.

Ssee docs here about this

> **[GitHub - mcneel/Rhino.Testing: NUnit dotnet unit testing for Rhino3D](https://github.com/mcneel/Rhino.Testing/?tab=readme-ov-file#test-setup-fixture)**
>
> NUnit dotnet unit testing for Rhino3D

---

<div class="post-metadata">

**Author:** ![janotaondrej91](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/janotaondrej91/32/504618_2.png) [@janotaondrej91](https://discourse.mcneel.com/u/janotaondrej91)\
**Post date:** [October 4, 2024, 6:54am UTC](https://discourse.mcneel.com/t/rhino-testing/192259/4 "2024-10-04T06:54:23Z")

</div>

Thanks for your reply and advice. Most of the things now works. 😃

I have read the docs you mention, before I started to implement `[Rhino.Testing]`. However, If ‘[Rhino.Testing]’ library is installed via NuGet marking class `[RhinoTestFixture]` raises an error _Cannot apply attribute class RhinoTestFixture because it is abstract_. So, I left that option.  
This happens for my my test and even for this [sample](https://github.com/mcneel/SimpleRhinoTests).

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/1/c/b/1cb062709ca6951d7e1e606d0432fff82057515a.png)

When I look into Rhino.Testing repo itself `[RhinoTestFixture]` is used in some tests and works. Even if the attribute is `[RhinoTestFixture]` it points rather to the `[RhinoTestFixtureAttrbute class]` which is not marked as abstract.

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/6/2/e/62e7d4decf926ed13a1b17bd08ca08a88c7b6507.png)

I tried to add `[Rhino.Testing]` project to my solution and reference it as a project not via NuGet. And it works (stops to raise error with abstract class). So it looks like there is a difference between nuget version and a github and downloaded version.

Both says version 8.0.023.0

Am I missing something else?

Thanks

Ondřej

---

<div class="post-metadata">

**Author:** ![CallumSykes](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/callumsykes/32/569341_2.png) [@CallumSykes](https://discourse.mcneel.com/u/CallumSykes)\
**Post date:** [October 4, 2024, 4:57pm UTC](https://discourse.mcneel.com/t/rhino-testing/192259/5 "2024-10-04T16:57:09Z")

</div>

Would you be able to share your project, or a stripped down version @janotaondrej91, I’m trying to reproduce your issue, but I can’t seem to.

---

<div class="post-metadata">

**Author:** ![janotaondrej91](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/janotaondrej91/32/504618_2.png) [@janotaondrej91](https://discourse.mcneel.com/u/janotaondrej91)\
**Post date:** [October 7, 2024, 6:16am UTC](https://discourse.mcneel.com/t/rhino-testing/192259/6 "2024-10-07T06:16:57Z")

</div>

No problem. However, I tried to reproduce error as well and changed `Rhino.Library` reference back to NuGet package. It works back so I can’t reproduce it as well. I will let you know if it appear again.

Thank you very much for help.

Ondřej

---

<div class="post-metadata">

**Author:** ![richard.aubin](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/richard.aubin/32/502374_2.png) [@richard.aubin](https://discourse.mcneel.com/u/richard.aubin)\
**Post date:** [November 8, 2024, 7:12am UTC](https://discourse.mcneel.com/t/rhino-testing/192259/7 "2024-11-08T07:12:09Z")

</div>

Is this library able to be used with Rhino 7 and net48?

---

<div class="post-metadata">

**Author:** ![gruedisueli](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/gruedisueli/32/556538_2.png) [@gruedisueli](https://discourse.mcneel.com/u/gruedisueli)\
**Post date:** [February 18, 2025, 12:01am UTC](https://discourse.mcneel.com/t/rhino-testing/192259/8 "2025-02-18T00:01:58Z")

</div>

Is there some way _ **not** _ to run Rhino headless? I want to do some UI testing but I also want access to certain parameters of my plugin. I want to have some kind of hybrid test that opens the Rhino UI and clicks on things, but also “knows” about what Rhino is doing under the hood.

---

<div class="post-metadata">

**Author:** ![CallumSykes](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/callumsykes/32/569341_2.png) [@CallumSykes](https://discourse.mcneel.com/u/CallumSykes)\
**Post date:** [February 18, 2025, 7:20am UTC](https://discourse.mcneel.com/t/rhino-testing/192259/9 "2025-02-18T07:20:25Z")

</div>

I have used the NUnitTestRunner [NUnitTestRunner](https://github.com/structurecraft/nunittestrunner) (quite extensively) in the past for running commands and complex end to end tests in a CI/CD System.

---

<div class="post-metadata">

**Author:** ![gruedisueli](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/gruedisueli/32/556538_2.png) [@gruedisueli](https://discourse.mcneel.com/u/gruedisueli)\
**Post date:** [February 18, 2025, 12:20pm UTC](https://discourse.mcneel.com/t/rhino-testing/192259/10 "2025-02-18T12:20:20Z")

</div>

Thanks, it is wpf plugin and the goal is to test the UI buttons, etc. in an automated way, so that’s why I want to actually have the Rhino window physically open rather than headless.

---

<div class="post-metadata">

**Author:** ![CallumSykes](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/callumsykes/32/569341_2.png) [@CallumSykes](https://discourse.mcneel.com/u/CallumSykes)\
**Post date:** [February 18, 2025, 12:45pm UTC](https://discourse.mcneel.com/t/rhino-testing/192259/11 "2025-02-18T12:45:22Z")

</div>

If you’re going to run it on a CI/CD machine, just note that physically moving the actual mouse cursor around with code will likely fail at some point as some random window will get in the way. If you can, invoke the things you’d like to click or interact with via code.

---

<div class="post-metadata">

**Author:** ![janotaondrej91](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/janotaondrej91/32/504618_2.png) [@janotaondrej91](https://discourse.mcneel.com/u/janotaondrej91)\
**Post date:** [February 18, 2025, 1:32pm UTC](https://discourse.mcneel.com/t/rhino-testing/192259/12 "2025-02-18T13:32:23Z")

</div>

I was able to test WinForms forms by classic unit tests with XUnit. All forms and buttons was invoked by code without running Rhino at all. However, all the input was not Rhino geometry/elements.

---

<div class="post-metadata">

**Author:** ![gruedisueli](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/gruedisueli/32/556538_2.png) [@gruedisueli](https://discourse.mcneel.com/u/gruedisueli)\
**Post date:** [February 18, 2025, 2:16pm UTC](https://discourse.mcneel.com/t/rhino-testing/192259/14 "2025-02-18T14:16:51Z")

</div>

How did you invoke the buttons? Did you send click events to them via a specific library?

---

<div class="post-metadata">

**Author:** ![janotaondrej91](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/janotaondrej91/32/504618_2.png) [@janotaondrej91](https://discourse.mcneel.com/u/janotaondrej91)\
**Post date:** [February 19, 2025, 8:17am UTC](https://discourse.mcneel.com/t/rhino-testing/192259/15 "2025-02-19T08:17:37Z")

</div>

No, did not use any specific library. For the debug env. I set buttons, methods (linked to the click event) and all necessary stuff to be internal. Then I can use it in the test as following:

```auto
 [Fact]
 public void ConnectButton_Click_WithXLSXConnectionType_FileDoesNotExist_ShowErrorMessage()
 {
     // Arrange
     var form = new ConnectIbForm();
     form.ConnectionTypeCBox.SelectedIndex = 0;
     form.PathToFileTBox.Text = "NonExistentFile.XLSX";
     form.ConnectionNameTBox.Text = "TestConnection";

     // Act
     form.ConnectButton_Click(null, EventArgs.Empty);

     // Assert
     Assert.Null(form.Connection);
 }

```

I am not sure if I follow best practices regarding unit testing but it brings the result.

For the interaction with the Rhino/GH I have second project in which I use [tmakin/RhinoCommonUnitTesting: Example of unit testing RhinoCommon from within the Visual Studio test runner on windows](https://github.com/tmakin/RhinoCommonUnitTesting) this repo as a source.

I have also tested Rhino.Testing but I have few problems which I was not able to solve.

At the end of the day I ended using different repo/library for different use case in on solution. What I need to add to have all the tests is to test GHScripts and RhinoCommands directly in the Rhino/GH but without Rhino/GH running graphically.

Ondřej

---

<div class="post-metadata">

**Author:** ![gruedisueli](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/gruedisueli/32/556538_2.png) [@gruedisueli](https://discourse.mcneel.com/u/gruedisueli)\
**Post date:** [February 20, 2025, 2:16pm UTC](https://discourse.mcneel.com/t/rhino-testing/192259/17 "2025-02-20T14:16:47Z")

</div>

Thanks all to the replies! I’m having pretty good luck doing action recording in my plugin, and replaying using a standard VS Unit Test csproj, along with [flaUI](https://github.com/FlaUI/FlaUI), for managing the clicking of Xaml elements. I tried WinAppDriver but I had some issues, probably because it has been discontinued. Anyways, flaUI seems very robust for the task-at-hand. In terms of interacting with non-XAML elements I had to develop a small api accessed via a Rhino command that runs various plugin-specific operations. The UI replay test both clicks XAML elements and types things into the Rhino command line.
