views:

436

answers:

2

I've built a unit test project for a library in VS 2008 C#. The library will react to commandline arguments. I have set the unit test's Properties -> Debug -> Start Options with default arguments to trigger specific reactions in the target library. My questions are:

1) When the library code executes Environment.GetCommandLineArgs() it does not see any of the default arguments I have set. I have even copied the default arguments from the unit test project to the library project's Properties with no effect. What am I not doing (right)?

2) Is there a programatic way to set the command line arguments? I would like the various tests to be able to set the args and watch the library behavior.

Thank you, Jim

+1  A: 

Hi, it doesn't directly answer your question, but I would recommend not using command line args in a library. Command line args should be parsed by the executable, and then proper parameters passed down to the library. In the case of unit tests you can simply pass test arguments. Think about using your library in a GUI application where the user inputs parameters in a form instead of command line args, or about a program using your library twice in two different ways.

Grzenio
Excellent point; you are absolutely correct. I should have made it clear that the library _is_ the commandline analyzer for applications. It will provide commonality to the interpretation of commandline and .config settings.
Jim Roberts
A: 

Found the problem. The ReSharper add-on is running its TaskRunner.exe to execute the unit tests. The commandline when TaskRunner is invoked does not take the debug settings into account. JetBrains (manufacturer) is now aware of this problem.

Jim Roberts