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

now he who must not be named. picture now he who must not be named. · Jul 17, 2013 · Viewed 10.2k times · Source

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.

Answer

Jeff Lewis picture Jeff Lewis · Mar 15, 2015

You can use TestContext.CurrentContext.TestDirectory as mentioned by Charlie Poole from NUnit here.

Reference: https://stackoverflow.com/a/29057351/589574