开发者

nUnit Test function which uses executable path to open a file

开发者 https://www.devze.com 2022-12-11 17:46 出处:网络
I have a function which opens up the help file for the app. The function takes 3 arguments : ShowHelp(appPath, 1,

I have a function which opens up the help file for the app. The function takes 3 arguments :

ShowHelp(appPath, 1, @"heelp\help.doc")

  • The first argument is the start path.
  • The second argument is the no of levels up the start path.
  • The third argument is the path of the help file after going up n levels from the start path.

To test this I created a Resources folder in my test project, added a doc into this folder and supplied the below:

controller.ShowHelp(Application.ExecutablePath, 1, @"Resources\h.doc");

However when I run this thru test driven.net , my executable path is coming back as :

"C:\Program Files\TestDriven.NET 2.0\ProcessInvocation.exe"

  • How do I supply the path of my Test Project i开发者_如何学运维n the test?
  • Is there any easier way to test this method?

Thanks!


If you use

Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)

you should obtain the path for the library containing the tests, probably something like (..\bin\Debug), and then you can adapt the other parameters.


you should make your path relative.

http://blogs.lessthandot.com/index.php/DesktopDev/MSTech/application-startuppath-and-nunit?highlight=application.startuppath&sentence=

in other words replace the application.executablepath with "/". See blog for more detail.

0

精彩评论

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

关注公众号