Search code examples
c#unit-testingnunit.net-4.5shadow-copy

Getting the desired / correct assembly path while unit testing with NUnit


I just started experimenting moq for unit testing my modules.

Actually, the class for which I have to write an unit test uses

Assembly.GetExecutingAssembly().Location internally to determine a path.

But, this doesn't work while writing unit tests because, the path of the executing assembly is different (the path of the unit testing assembly is taken)

AppData\\Local\\Temp\\3ylnx32t.ukg\\TestApplication.Test\\assembly\\dl3\\aeb938e6\\f3664631_d982ce01.

I tried, disabling shadow copying.

AppDomainSetup appDomain= new AppDomainSetup{ShadowCopyFiles = "false",};
appDomain.ShadowCopyFiles=false.ToString();

still, it doesn't work!

Any suggestions are appreciated. Thanks in advance.


Solution

  • Finally, I accomplished this through this way:

    I used NUnit Framework and disabled Shadow copying in NUnit. Created a copy of my configuration file in that directory where the unit testing library is invoked.

    So, whenever my unit test is invoked (say from path 'A'), my application doesn't complain that there is no configuration file in that location since i put my configuration file in path 'A'.

    (ps: The reason why I get the assembly location is to be able to find my configuration file in that location)

    [The whole idea is this: with shadow copying, the assembly path is dynamic. disable it and the assembly path is static]