views:

667

answers:

4

In a Test project in Visual Studio 2008 (Pro), I created a Test project, and I want to configure the project properties to give a command line argument to the tests. I set the properties, but then realized I have no idea how to actually use the argument.

How do you get the arguments from MSTest?

A: 

Perhaps you can use GetCommandLine().

Edit: GetCommandLine() is a win32-function, but there ought to be a corresponding .Net function for it.

JesperE
+1  A: 

Ben,

What do you need the arguments for? I'm having a hard time thinking of a scenario where I'd need a command line argument for my unit tests.

Esteban Araya
A: 

VS 2008 test are compiled into DLLs which can't directly receive command line arguments as far as I know.

You could add a configuration file 'app.config' for the dll and use that instead.

Just beware, mstest only copies .config files for the test container being run at the time.

if you have the following...

mytest.dll
mytest.dll.config
lib.dll
lib.dll.config

and you reference lib.dll from mytest.dll, when you run the tests lib.dll.config will not get copied and your test may fail because of this.

JTew
A: 

@Esteban Araya: I've since re-thought how I was writing my tests; all the data I need is baked-in now, so I don't need the command line args.

I've also ditched MSTest now, in favor of NUnit+TestDriven.NET

Ben Collins