Is there a possibility to set the command line arguments in unit tests in VS2012? If not, is there an alternative to test many combinations of such arguments besides writing a batch file?
EDIT: I have a console program which reads and parses the passed command line arguments. I would like to assure that the program has the proper behaviour no matter what command line arguments are passed. Instead of trying all combinations over and over again I would like to write a unit test which sets the arguments and starts my program with them.
I don't use any specific test framework. Just the one provided in Visual Studio by creating a new test project.
It is possible to pass custom command line arguments to the test module.
What are Command Line Arguments in C? Command line arguments are nothing but simply arguments that are specified after the name of the program in the system's command line, and these argument values are passed on to your program during program execution.
Why not extract the parsing logic to a separate class and unit test that separately from your main ()?
The parsing class should receive string parameters. Therefore you can test as many scenarios as you need in different tests without actually having to run the program executable, just calling the class instead.
UPDATE:
Now, if you don't want to create an extra class (I would probably still do it, just for clarity, but anyhow), take into account that you CAN just call your static Main(string[] args)
method from your unit test, passing different parameters to cover different scenarios.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With