Set command line arguments in unit tests in C #

Is it possible to set command line arguments in unit tests in VS2012? If not, is there an alternative to testing many combinations of such arguments besides writing a batch file?

EDIT: I have a console program that reads and parses passed command line arguments. I would like to assure that the program has the correct behavior no matter what command line arguments are passed. Instead of repeating all the combinations over and over, I would like to write a unit test that sets the arguments and runs my program with them.

I do not use any specific test structure. Only the one provided in Visual Studio by creating a new test project.

+4
source share
1 answer

Why not extract the parsing logic into a separate class and unit test, which is separate from your main ()?

The parsing class should receive string parameters. Therefore, you can test as many scripts as you need in different tests, without having to run the program executable, just by calling the class instead.

UPDATE

Now, if you do not want to create an additional class (I would probably still do this, just for clarity, but somehow), keep in mind that you can just call your static Main(string[] args) method from your unit test, passing various parameters to cover various scenarios.

+4
source

Source: https://habr.com/ru/post/1486800/


All Articles