Acdbmgd.dll exceptions when Unit Testing

Acdbmgd.dll exceptions when Unit Testing

Anonymous
Not applicable
1,692 Views
7 Replies
Message 1 of 8

Acdbmgd.dll exceptions when Unit Testing

Anonymous
Not applicable

I have a Visual Studio C# project which generates a DLL file for AutoCAD.

 

I created another project in the same solution, which is a testing project so I can run some unit tests using NUnit on some methods. 

 

If I compile both projects as x86 and I use NUnit x86 I get System.BadImageFormatException on Acdbmgd.dll

 

If I do the same on x64 I get System.IO.FileNotFoundException on Acdbmgd.dll

 

Does anyone know what I am doing wrong? Thank you.

 

If you need more information just ask.

0 Likes
Accepted solutions (1)
1,693 Views
7 Replies
Replies (7)
Message 2 of 8

norman.yuan
Mentor
Mentor

If your code snippet uses AutoCAD APIs, then you cannot really do a "UNIT" test. The test can only run with AutoCAD itself being integrated (thus, the test is INTEGRATED TEST), because all the classed in Acdbmgd.dll only available in a running AutoCAD process.

 

So, doing real "unit test" with AutoCAD add-in code is very difficult and tricky. One needs to structure the code properly to separate the portions of code that are "unit-test-able" (i.e. some business logic that does not involve AutoCAD). As you can see, for most part of AutoCAD add-in code, separating the code into "unit-test-able" (without AutoCAD involved) is really hard, sometimes not possible/not realistically doable, IMO.

 

In your case, if you still want to test with your existing AutoCAD .NET code, your test project must run AutoCAD, which effectively turn your "unit" test into "integration test", but, it may still better than "no test", right? Or you take pains to re-organize the code in your AutoCAD add-in DLL project, and to only flag code that has nothing to do with AutoCAD .NET API as testable and only test that portion of code (I guess there would not be much code left as "test-able").

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 8

norman.yuan
Mentor
Mentor

Also, there may be third party test tool available to help integrate apps, such as AutoCAD, into the test process, so that you can test your code like "Unit Test" (while behind the scene, it is integration test, anyway). I have never bothered to try. 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 4 of 8

Anonymous
Not applicable

I created this simple C# solution with two projects.

 

One project imports acdbmgd.dll and has an method which just creates a Point3d variable (doesn't even use it).

 

The other project is a testing project and tries to assert true calling the method from the other project first. 

 

The thing is I get the error mentioned in the original post and I don't think I should be getting it.

 

I uploaded the solution to Google Drive if you'd like to try it yourself... I would really appreciate it.

 

https://drive.google.com/open?id=1u9SxazxFHbA3x8e9xxK27bS5oDagC4yc

0 Likes
Message 5 of 8

norman.yuan
Mentor
Mentor
Accepted solution

I am not sure whether you get my point or not: AutoCAD .NET API assemblies (acdmmgd.dll...) can ONLY be USED WHEN LOADING INTO AutoCAD process.

 

In your case, your test project that loads your DLL project (to test), which has acdbmgd.dll referenced. Whether the code actually has Point3d actually used or not, the acdbmgd.dll has to be loaded into memory of "NON-AutoCAD" process, thus the error, meaning you CANNOT use Acdbmgd.dll in ANY WAY outside AutoCAD process.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 6 of 8

kerry_w_brown
Advisor
Advisor

Norman,

I have a Beach Boys ditty running aroungd in my head ..


 

And then we'd be happy (and then we'd be happy)
Oh, wouldn't it be nice?




// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
0 Likes
Message 7 of 8

CADbloke
Advocate
Advocate

Try https://github.com/CADbloke/CADtest - it runs NUnit inside AutoCAD.

- - - - - - -
working on all sorts of things including www.tvCAD.tv & www.CADreplace.com
0 Likes
Message 8 of 8

kerry_w_brown
Advisor
Advisor

Ewen, have you tried that with current builds ?


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
0 Likes