Including Plugin Project crashes Rhino.Testing

Hello,

I’m trying to test a Rhino plugin
some of the objects that I need to interact with must be created in the plugin in order to be valid
so I wanted to be able to unit test the rhino plugin directly

we use Rhino.Testing to handle some of our unit tests

is there a way to interact with our plugin objects?
I tried to include my plugin project in a testing project using Rhino.Testing but that appears to crash the testing framework

I created an empty wpf plugin to see if I could recreate it
and it fails with this message

========== Starting test discovery ==========
Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Testhost process for source(s) 'C:\RhinoExamples\EmptyPluginForTesting\SampleTestProject\bin\Debug\net7.0-windows\SampleTestProject.dll' exited with error: Failed to create CoreCLR, HRESULT: 0x80070057
. Please check the diagnostic logs for more information.
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.ThrowOnTestHostExited(IEnumerable`1 sources, Boolean testHostExited) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs:line 520
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources, String runSettings) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs:line 294
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyDiscoveryManager.InitializeDiscovery(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler, Boolean skipDefaultAdapters) in /_/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyDiscoveryManager.cs:line 149
========== Test discovery aborted: 0 Tests found in 84.3 ms ==========

this is my setup fixture


namespace SampleTestProject
{
    [SetUpFixture]
    public class SetupFixture : RhinoSetupFixture
    {
        public override void OneTimeSetup()
        {
            var rhinoDir = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\McNeel\Rhinoceros\8.0\Install", "Path", null) as string ?? string.Empty;
            var plugin =
                "C:\\RhinoExamples\\EmptyPluginForTesting\\EmptyPluginForTesting\\bin\\Debug\\net7.0-windows\\EmptyPluginForTesting.rhp";
            plugin = plugin.Trim('"');

            Assert.True(Directory.Exists(rhinoDir), string.Format("Rhino system dir not found: {0}", rhinoDir));
            Assert.True(File.Exists(plugin), string.Format("Rhino plugin file not found: {0}", plugin));

            var xml = $@"<?xml version=""1.0"" encoding=""utf-8""?>
<Settings>
	<RhinoSystemDirectory>{rhinoDir}</RhinoSystemDirectory>
</Settings>
<LoadPlugins>
	<Plugin Location=""{plugin}""/>
</LoadPlugins>
";
            File.WriteAllText("Rhino.Testing.Configs.xml", xml);
            base.OneTimeSetup();
        }

        public override void OneTimeTearDown()
        {
            base.OneTimeTearDown();
        }
    }
}

and this is the sample test I was trying to run

using NUnit.Framework;

namespace SampleTestProject
{
    [TestFixture]
    public class TestFile : Rhino.Testing.Fixtures.RhinoTestFixture
    {
        [Test]
        public void TestCircle()
        {
            Assert.True(true);
        }
    }
}

Is there some other way I’m missing to unit test a plugin directly?

1 Like

I’d also be curious to know this!

EmptyPluginForTesting.zip (2.4 MB)

This is the mostly empty project I used to demonstrate this, if it helps

Here

If you want to load your own plugin from a custom location, you either

  • hardcode the absolute rhp file path in the Rhino.Testing.Config.xml
    OR
  • load the rhp plugin by yourself within OneTimeSetup(): Rhino.PlugIns.PlugIn.LoadPlugIn(rhpPath, out var guid)

Hello,

I updated the sample project to copy a Rhino.Testing.Config.xml file and it still seems to fail to run the test
If I remove the reference to the Plugin project, the test attempts to run
is there anything I could be missing?

How do you reference your plugin project? I can guess that you didn’t set the private to false for your plugin projects. Adding plugin’s rhp files to the test project’s output bin folder would cause conflict issues.

Here is how you can reference your plugin plugin in the unit test project.


Then, use LoadPluign to load your own plugin in the SetupFixture’s OneTimeSetup().

1 Like