Showing results for 
Search instead for 
Did you mean: 

using Microsoft.VisualStudio.TestTools.UnitTesting;


Does anyone know how to implement unit testing using the framework in my Subject line? Or any other framework like NUnit?

I am trying to implement Test Driven Development with my user functions but I can't figure it out since all the programs need to be called from NX.

Any information would be greatly appreciated.

Thank You.


Re: using Microsoft.VisualStudio.TestTools.UnitTesting;

Siemens Phenom Siemens Phenom
Siemens Phenom


You will need to add a Reference to the .dll.  Use the Browse button.


I found it under C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll


Obviously your path might be different, but I think that is the .DLL that you need.

Re: using Microsoft.VisualStudio.TestTools.UnitTesting;

I understand the problem is how do I run the test with NX?
Because NX calls the user functions, I can't test the methods that I want to test with the unit framework.
And since the framework doesn't operate with a "Main" method. I can't run the test cases/Class by calling it from NX.
Anything that references a function or a variable or anything the relates to NX results in a "BadImageFormatException".
This is because when you run the tests there is no session of NX loaded.

Is there any way to accomplish what I am looking for that you know of?
Or any sort of direction that I can be pointed.
Thanks a bunch.

Re: using Microsoft.VisualStudio.TestTools.UnitTesting;

Siemens Phenom Siemens Phenom
Siemens Phenom

Sorry - I didn't understand what you were asking.  Is your program a .DLL or a .EXE?


If you build your code as a console application (.EXE), and run it in an environment where all of the required UGII... and UGS... variables are defined, then as soon as it hits GetSession(), you have an NX session in memory - although you will not see NX on the screen anywhere.  Then calls to NXOpen routines should work.


If you are trying to run a .dll in the debugger, you might need to Attach to Process, and select the ugraf.exe.

Re: using Microsoft.VisualStudio.TestTools.UnitTesting;


SteveLabout, I don't see how this answers the question about using visual studio unit testing with NX Open.


Compiling the unit test creates a dll, but you cannot attach it to the ugraf.exe process and then run it from NX (ctrl+u) because it does not have an entry point for NX.


So as a work around I added a Main and a GetUnloadOption to the unit test project. This allows me to run it from NX, but then the visual studio test explorer isn't used to run, manage and show the test results.


Does anyone have any better solutions?


Re: using Microsoft.VisualStudio.TestTools.UnitTesting;

PLM World Member Legend PLM World Member Legend
PLM World Member Legend

Hi @Nathaniel


Once you have created the unit test project and added your test methods, then close the solution file and open the *.sln file from the NX console window. Modify the test settings as shown below:




Now you can able to run the test successfully (BadFormatImageException will be resolved) by following the above methods.


Unit tests are not required MAIN function to execute the tests. Test Initialize / TestCleanup attributes helps you to initialize the Session or UFSession and unload the libraries.