tmakin / RhinoCommonUnitTesting

Example of unit testing RhinoCommon from within the Visual Studio test runner on windows
35 stars 14 forks source link

Manual load of GH libraries when not using packages.config #7

Open marios-tsiliakos opened 3 years ago

marios-tsiliakos commented 3 years ago

@tmakin I think I figured out why we need to manually load the Grasshopper.dll even though Rhino.Inside should load it by default. I audited where the assemblies are loaded from and it seems that Rhino.Inside looks for them in the bin folder when it runs the tests. Without using a package.config file - with the new .csproj format - these are not copied in the build directory, so our tests fail to load them. I added a new project using the old format rhino.inside loads everything fine. https://github.com/marios-tsiliakos/RhinoCommonUnitTesting/blob/9f8569ec59a7d2101d5af3b7c6b4b19d20035ad8/Src/RhinoPlugin.Tests.RHInside/XunitTestFixtureRI.cs#L21-L39 Also when I tried to run the Xunit tests again and the GH one was failing because GH_IO.dll wasn't loaded so fixed that here: https://github.com/marios-tsiliakos/RhinoCommonUnitTesting/blob/9f8569ec59a7d2101d5af3b7c6b4b19d20035ad8/Src/RhinoPlugin.Tests.Xunit/XunitTestFixture.cs#L65-L86 Let me know if you want to address any of these in a formal PR.

paireks commented 3 years ago

Hi @marios-tsiliakos!

I also had this issue with the Grasshopper.dll.

Do I understand correctly, that to use your solution, the additional nuget package (Rhino.Inside) is necessary to be installed? Is there any other requirements?

marios-tsiliakos commented 3 years ago

Hi @paireks , The current state of the master file is using the rhino.inside nuget package. So by using your tests should be executed fine and rhino loading properly. The Grasshopper.dll still needs need to be loaded manually. As vs cannot find it and load it from the build directory After doing some digging up I found that the reason for this is that in one f the previous PRs we switched to the new .csproj format-this "fails" to copy the GH dependencies in the build folder hence you have to manually load them into the test context. If you use the old project format the solution is working fine and you don't need to load anything - Rhino.Inside is taking care of that. https://github.com/marios-tsiliakos/RhinoCommonUnitTesting/blob/9f8569ec59a7d2101d5af3b7c6b4b19d20035ad8/Src/RhinoPlugin.Tests.RHInside/XunitTestFixtureRI.cs#L21

feel free to use the above if you don't migrate to the new format.

paireks commented 3 years ago

Oh, ok now I see, I was using a version from 2020 when there was no Rhino.Inside required already, that's why I was confused :) Thank you for help! I will check it out once I will find some time ;)

tmakin commented 3 years ago

@marios-tsiliakos Would you be able to PR a fix or relevant documentation for this?

marios-tsiliakos commented 3 years ago

@tmakin Sure. Will do later this week. I think the documentation is more important in this case but I will include a project using the old .csproj format that works as expected.

paireks commented 3 years ago

Yeah, some documentation will help a lot. I just tried new fixture but couldn't get it to work, but I guess it's because I'm missing something. Should it work also for multiple test classes?

marios-tsiliakos commented 3 years ago

@paireks yes it works with multiple test classes. They just have to be decorated with the same/correct test collection attribute.