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

    Question

  • 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

     

    Thursday, March 30, 2006 3:02 PM

Answers

  • 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

    Friday, March 31, 2006 2:18 AM
    Owner

All replies

  • 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

    Friday, March 31, 2006 2:18 AM
    Owner
  • Thank you for your answer. I guessed that was the case, just wanted to be sure...
    Sunday, April 02, 2006 6:53 AM
  • It would be really nice if mstest could pass command line arguments to the test classes via the TestContext class.
    Wednesday, June 28, 2006 3:06 PM