Unit testing for Dynamo - Updated version available?

Hi guys,

I was looking into the Dynamo testing posibilities to see what I could create to test the Dynamo package that I’ve been working on (specifically at How to write tests for a package).

https://developer.dynamobim.org/04-Testing/4-0-testing.html

I’m having some trouble setting this up:

  1. When I create my own test assembly the tests don’t run at all. I get a message saying “Test run finished in … ms. 0 Total tests - 0 Passed, 0 Failed, 0 Skipped”

  2. When using the assembly ‘SampleLibraryTests’, all tests fail, with error messages like this:

    PassingTest
    Duration: 845 ms

    Message:
    System.NotImplementedException : Method ‘SetAttributes’ in type ‘Autodesk.LibG.CurveHost’ from assembly ‘LibG.ProtoInterface, Version=2.9.0.3355, Culture=neutral, PublicKeyToken=null’ does not have an implementation.
    Stack Trace:
    HostFactory.get_Factory()
    Point.ByCoordinates(Double x, Double y, Double z)
    HelloDynamoZeroTouchTests.PassingTest() line 46

Is anyone able to help? Perhaps there is an updated version of the testing page on Gitbook?

Thanks if anyone can help! It is much appreciated.

Michael

SetAttributes is a new internal api - I don’t believe it is in anything released (I think the error basically means the version of the geometry library that is being loaded during the test doesn’t have this method, we’ve only seen this error in our dev builds - so are you using a 2.11 or 2.12 daily build of dynamo?
I would try to get a later one - or perhaps one of the stable builds.

also - for the test nugets

Make sure the version of SampleLibraryTests matches your dynamo version closely ie use 2.x which matches your 2.x version of Dynamo.

2 Likes

Hi Michael,

Thanks for helping me :sunglasses:

I used Dynamo 2.10.1.3976 (stable) and the matching NuGet versions.

I tried using Dynamo 2.8 (updated the NuGet packages to the matching version) and updated TestServices.dll.config to:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="DynamoBasePath" value="C:\Users\vantelgm7702\OneDrive - ARCADIS\Michael\Dynamo\00. Dynamo versions\2.8"/>
    <add key="RequestedLibraryVersion2" value="226.0.0"/>
  </appSettings>
</configuration>

But I get the same message:

 PassingTest
   Duration: 718 ms

  Message: 
    System.NotImplementedException : Method 'SetAttributes' in type 'Autodesk.LibG.CurveHost' from assembly 'LibG.ProtoInterface, Version=2.8.0.2374, Culture=neutral, PublicKeyToken=null' does not have an implementation.
  Stack Trace: 
    HostFactory.get_Factory()
    Point.ByCoordinates(Double x, Double y, Double z)
    HelloDynamoZeroTouchTests.PassingTest() line 46

I checked out the LibG.ProtoInterface assembly that is installed in the Dynamo folder and it doesn’t contain a method called SetAttributes. Could this be the issue? I’m not sure, I have no with unit testing at all…

Could anything else be the problem or could I be missing something?

Thanks again,

Another thought: I know that in VS 2019 the menu bar was restructured. Mine looks like this. Is this correct?

Instead of:

  1. Do you have a working version of Dynamo that creates geometry on your machine?

  2. I would also try moving dynamo out of your one drive, and make sure to unzip it with 7zip or sufficiently unblock it.

  3. 226 corresponds to year 2020 products, do you have a year 2020 product like Revit installed?

that x64 setup looks okay.

If you simply can’t get this working -
another option is this:

though I have not tested it in a long time… you would not use geometricTestBase if you went this manual route.

Hi Michael, sorry for the late reply.

I have a couple of different Dynamo versions (2.1, 2.4, 2.8, 2.9 and 2.10) that all work well (including geometry creation). I use them to test my package whenever there is a big update.

Will check if the folder location is an issue today. I have Revit versions 2019, 2020 and 2021 installed atm.

I didn’t have 7zip so I used Powershell to unblock all files:

Get-ChildItem -Path ' path here ' -Recurse | Unblock-File

Could that make a difference? Will update later today, thanks again!

We recently found a bug in the geometry library lookup that the geometric test base (and sandbox) use - another thing you can try is to use the latest pre release 2.12 nugets where the bug should be fixed.

I don’t think the powershell unblock would cause an issue, it’s just harder to get right :slight_smile:

Hi Michael,

Running Dynamo from another folder didn’t help, neither did getting the beta nugets unfortunately.

I managed to get a step further with my own test assembly though (I had set nunit.framework to copy local = false by accident), or at least I get another error message than before. Does this shed any light on what the problem might be?

 PassingTest
   Source: Class1.cs line 19
   Duration: 4,2 sec

  Message: 
    SetUp : System.TypeInitializationException : The type initializer for 'Autodesk.DesignScript.Geometry.HostFactory' threw an exception.
      ----> System.IO.FileNotFoundException : Could not load file or assembly 'LibG.Interface, Version=2.11.0.4226, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
  Stack Trace: 
    HostFactory.get_Instance()
    IExtensionApplication.OnBeginExecution(IExecutionSession session)
    GeometricTestBase.Setup()
    --FileNotFoundException
    HostFactory.ctor()
    HostFactory.cctor()