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. However, it did not worked well and I left that approach. Issues are described in here (1 and 2 ).
Finally, I have found Rhino.Testing library which looks very promising. There are also the SampleTests 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 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. 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.
Class for the test is quite simple:
[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 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):
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