English 中文(简体)
nUnit Test function which uses executable path to open a file
原标题:
  • 时间:2009-11-19 11:22:05
  •  标签:
  • c#
  • tdd
  • nunit

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

ShowHelp(appPath, 1, @"heelphelp.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, @"Resourcesh.doc");

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

"C:Program FilesTestDriven.NET 2.0ProcessInvocation.exe"

  • How do I supply the path of my Test Project in 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 (..inDebug), 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.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签