Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6138545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:52:52+00:00 2026-05-23T17:52:52+00:00

Is there a way to pass command line arguments to the application cotext during

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:52:52+00:00Added an answer on May 23, 2026 at 5:52 pm

    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:

    1. You need a class which is parser and holder for CLI agruments. In my case it is astatic class with static properties. Of course it was returning null values during unit testing (no recognized CLI arguments)
    2. 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.

      public static class MyCLIArgsHandler
      {
           private string mAppName = null;
           private string mStationName = null;
      
           public string StationName
           {
               get
               {
                   if(string.isNullOrEmpty(MyCLIArgsHandler.mStationName))
                   {
                      //PARSE CLI ARGS
                   }
                   return MyCLIArgsHandler.mStationName;
               }
           }
           //...
      }
      
    3. Before you start actuall testing you can inject sample values to fields of that class so when:

      [ClassInitialize()]
      
      public static void MyClassInitialize(TestContext testContext)
      {            
          PrivateType type = new PrivateType(typeof (MyCLIArgsHolder));
          type.SetStaticFieldOrProperty("mAppName", "myTestAppName");
          type.SetStaticFieldOrProperty("mStationName", "myTestStationName");
      }
      

    Voila!

    Now all your classes can use your MyCLIArgsHolder with values you put in your test class initialization.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there some way to pass system commands along with command line arguments in
Is there any way to pass command line parameters to a Flash projector in
I'm testing some python code that parses command line input. Is there a way
Is there a way to pass null arguments to C# methods (something like null
Boost.Program_options provides a facility to pass multiple tokens via command line arguments as follows:
Is there a way to pass named arguments to a Ruby script? I understand
I'm trying to create a script/application which accepts command line arguments when run. Of
How do I pass the command line arguments to an alias? Here is a
The problem is that I have n command-line arguments. There are always going to
Currently I am trying to pass some values through command line arguments and then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.