开发者

File.Exists("SDF File Path") returns a FALSE when run through Unit tests even though it exists in the Execution Directory

开发者 https://www.devze.com 2022-12-13 10:39 出处:网络
I am writing Unit tests for a Windows Project. The Executable project on the Client Side of this Windows Project has a code File.Exists(\"LanguageLookups.sdf\") which is used to check and return a Boo

I am writing Unit tests for a Windows Project. The Executable project on the Client Side of this Windows Project has a code File.Exists("LanguageLookups.sdf") which is used to check and return a Bool if the sdf file exists in the Execution Directory or not. But when i execute the same piece of Code through a Unit test; The code File.Exists("LanguageLookups.sdf") returns a FALSE. Its not able to fi开发者_开发技巧nd this SDF File. Can anybody help me on this?


You might want to check the current working directory of the unit test using Environment.CurrentDirectory. Your unit test runner most likely is not running your test with the same working directory as your Windows application, and therefore your unit test cannot find the file because it is looking in the wrong directory.


I'd guess that it's not running from the execution directory.
Use an absolute path and see if it works.


File.Exists docs talks about the GetCurrentDirectory() and building up an absolute path.

0

精彩评论

暂无评论...
验证码 换一张
取 消