2

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?

Nikita R.
  • 7,245
  • 3
  • 51
  • 62
Ben Collins
  • 20,538
  • 18
  • 127
  • 187

2 Answers2

1

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
  • 3,149
  • 3
  • 31
  • 39
  • However, if you want to you lib.dll.config with mytest.dll, you shouldn't create a new app.config file in MyTest project, but just add a link to Lib project app.config file as described here http://stackoverflow.com/a/2746836/182371 – Nikita R. Jun 18 '12 at 15:10
0

Perhaps you can use GetCommandLine().

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

JesperE
  • 63,317
  • 21
  • 138
  • 197