Unit Testing

Hi guys,

Do you know if Unit Tests still need to be run with Rhino.exe being the host process? i.e they are limited to being executed within Rhino? I was attempting to Unit Test a method I wrote which depends on RhinoCommon but when I try to run my tests in Visual Studio, XUnit throws some generic exceptions:

Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll
Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll
Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll

I suspect this could be because it can’t find rhcommon_c.dll ?

Also, before I started to include references in my test project to RhinoCommon, I was being able to test a method using native .NET types. After I referenced RhinoCommon, I could not run or debug any of the tests and I started getting the above exceptions from XUnit.

I am attempting to include Unit Tests in a CI Pipeline I have built in Azure Devops, and would like to know if it is possible to integrate this with RhinoCommon, or its simply not possible, due to the fact that any Unit Test dependant on RhinoCommon needs to be within a Rhino.exe process. Making Unit Testing code which depends on RhinoCommon impossible to automate in a CI pipeline.

All the references I have for my query is: is Unit testing plugin code

@stevebaer @Alain @dale perhaps you guys have more up to date info on this topic?

Thank you in advance and I will appreciate any further feedback on this.

Hi @rawitscher-torres,

This from @stevebaer in your referenced thread:

“The majority of RhinoCommon depends on functionality exported from the rhcommon_c.dll.
The rhcommon_c.dll depends on Rhino.exe.
Due to this dependency chain, Rhino.exe needs to be the host process.”

– Dale

Hi @dale

thank you for your prompt reply. So I guess that means that all Unit Tests in Rhino will have to lunch via a plugin, right? in Other words impossible to automate via a CI build pipeline.

Not if you use Rhino.Inside

1 Like

@rawitscher-torres,

I am using this project template, only restriction you cannot test anything related RhinoDoc. You can pass RhinoDoc.ActiveDoc property to moq your objects but don’t forget it will pass as null. So, you cannot add, remove objects from RhinoDoc.

For RhinoDoc related classes I am using integrated tests instead of unit tests.

Best

2 Likes

@oguzhankoral

Thanks for pointing this out, I was actually missing the part of LaunchInProcess of RhinoLibrary.dll that was the missing piece to emulate Rhino is the host of the process.

Hello,
@oguzhankoral I’m using the same template for Xunit.
It works pretty well except when I’m trying to user UserData, I can’t add user data to geometry or RhinoObject.
It may be related to the issue with ActiveDoc…
Does anyone knows if there’s a way to make it work?
Hugo.

Hi @Hugo3,

In these days we use this repo that you can run also RhinoDoc as headless mode (without running Rhino). I believe you can add UserData also to Geometry objects.

How you can’t achieve adding UserData? Can you give example with some code?

Best,
-Oğuzhan

Hi Thank you very much for the answer.
I’m also using this repo.
I’ve even succeeded to create an headless document.
But the issue occurs when i’m trying to add userdata to a RhinoObject or to a geometry.
It raises an nullReferenceException when it tryes to find the plugin linked to my userdata class :

I’ve tried to launch my plugin in the unit test doing this :

LoadPlugInResult result = PlugIn.LoadPlugIn(MyAssemblyFile, out Guid guid);
            switch (result)
            {
                case LoadPlugInResult.ErrorUnknown:
                    throw new Exception("Failed to load the plugin");
                case LoadPlugInResult.SuccessAlreadyLoaded:
                case LoadPlugInResult.Success:
                    break;
            }

It doesn’t raise any error (and my plugin constructor is well executed) but then my plugin is not found by this method :

PlugIn.Find(guid).GetPlugInObject()

I think the issue I’m facing is fully related to loading my plugin in a Xunit unit test.

Hey @Hugo3,

I’ve tried and not managed to test plugins with this method, this project will work better RhinoUnitTest .

Thank you @csykes, I will give it a try!