Setting command-line arguments for a unit-test project

Hi,

I need to perform unit-testing on classes that access the command-line arguments. In order to do that, I need to control the command-Line arguments.

Is there a way to do that (and still be able to run all the test automatically)

Thank you,

Sharon



Answer this question

Setting command-line arguments for a unit-test project

  • rabin

    It would be really nice if mstest could pass command line arguments to the test classes via the TestContext class.
  • Gary Halberstadt

    Thank you for your answer. I guessed that was the case, just wanted to be sure...
  • srjing2

    Hi Sharon277,

    I want to make sure I understand correctly. You have a command-line application with classes in it that refer to arguments they expect to be passed to the application at start, and you want to do unit tests against the methods in those classes

    The way those classes are instantiated so VS can do unit testing against them is entirely different than normal execution. The executable is not run like normal, and neither you nor VS can provide arguments to it.

    The classes are instantiated indepdently of program execution by using the binary as a class library.

    In order to set the properties of the command-line arguments you may need to consider adding a testing hook to access and set them, which you would use in the unit test after instantiation but before calling the methods.

    Cheers,

    David R. Williamson



  • Setting command-line arguments for a unit-test project