Is there a way to pass command line arguments to the application cotext during unit testing in Visual Studio 2008? Part of my code needs to be configured this way and i can only do this by passing arguments.
I’ve checked in the debug mode and command line arguments has been filled with some test related data.
Thanks!
Ok,
I was digging for a long time and was not able to find any way to pass CLI arguments directly.
However there is pretty nice workaround:
Your CLIArgsHolder class must be written in a sane way to return nulls and NOT throw exceptions when it initializes if any of CLI args is missing. In my case I parse only when private field is null or empty using static property’s get.
Before you start actuall testing you can inject sample values to fields of that class so when:
Voila!
Now all your classes can use your MyCLIArgsHolder with values you put in your test class initialization.