Using NUnit to test library with Rhinocommon

Hello all,

I am using NUnit for unit testing, but I am having trouble when I try to test objects that use Rhinocommon. I want to run rhino headless (seems like Rhino.Inside is the way to go?) so I can build this into a CICD pipeline.

I have checked out these samples online and tried to replicate how they work, but I still can’t get my tests working.
RhinoCommon Unit Testing
RhinoNUnitTestRunner

I made a simple dummy project to share to help figure out my issues. (attached)
NUnitHeadless-Dev.zip (2.3 MB)

It seems like StartRhino isn’t working or something has gone wrong earlier.

        [STAThread] // not sure if STAThread is required ??
        private void StartRhino()
        {
            _rhinoCore = new Rhino.Runtime.InProcess.RhinoCore(null, 
                Rhino.Runtime.InProcess.WindowStyle.NoWindow);
            _running = true;
        }

Thanks in advance for the help. I couldn’t find any recent samples, so hopefully this will be useful for others as well.

  • Jake

Hey @nacho_hero are you running windows or mac or linux?
AFAIK you can only currently unit test on Windows.

– cs

This is on windows 10 with Rhino 7 and visual studio 2022.

I’ve been writing a simpler rhino unit testing library for nunit. Here’s a sample.

[RhinoFixture]
public sealed class ExampleTests
{
	[TestCase]
	public void Brep_Translation()
	{
		// Arrange
		var bb = new BoundingBox(new Point3d(0, 0, 0), new Point3d(100, 100, 100));
		var brep = bb.ToBrep();
		var t = Transform.Translation(new Vector3d(30, 40, 50));

		// Act
		brep.Transform(t);

		// Assert
		Assert.AreEqual(brep.GetBoundingBox(true).Center, new Point3d(80, 90, 100));
	}
}

– cs

2 Likes

Awesome! I will check it out, and let you know how it works.

Thank you for letting me know.

1 Like

@csykes, your library works great!

I also figured out what I was doing wrong in my project… it was silly. I was using .Net Core.

Thank you for the help! I will be using your library going forward.

  • Jake
1 Like

I’ll be updating it so it supports mac + dotnet core as soon as Rhino is updated to allow for this :slight_smile:

Please add any issues you have to the github page and I’ll fix any you find.

I’m hoping to finalise and release all the CI/CD Unit Testing libraries and environments I’ve created and record a bit of a how-to guide.

– cs