views:

113

answers:

2

Hi

I am using VSTS Unitesting platform. I am trying to test a method which got references to assemblies which in turn contain DllImport to C++ DLLs.

In order for it to work I need to copy C++ DLLs to reside on the same directory the EXE and DLLs are running.

Of course when I use the same code with Unittest I also need to supply those DLLs. I found out that the Unittest framework us using the $(Solution)\TestResults[WorkSpace] [DateTime]\Out as a working directory.

If I manually copy the C++ DLLs to this directory the unit test is is working like a charm.

The problem is that every time the Unitest is running it creates a new directory.

Has anybody encountered it? do you have a solution?

Thanks, Ariel

A: 

You could try using a [DeploymentItem] attribute. It allows you to specify a relative path from the solution file which will get copied to the test output directory.

A: 

As Steve D mentions, deployment items are the answer here. You can either put them on the class, or test method using the attribute, or use the Test Run Configuration to add them so that when any tests are run from that solution they will be deployed.

The other option is to make sure they're in the path somewhere so that the standard windows look up rules for DLLs will apply, and the runtime will be able to locate them.

Why is this a problem? because theres little to no metadata from the project to the Native DLL -- we don't know to pick it up. The only option really would be to dive all types in the deployed managed dlls looking for the DllImport attrib. This would, however, fail, if you are doing explicit DLLLoads in the managed code.

dhopton