Freigeben über


Geek Speak: Testing Tip with VSTS

Situation: I am testing some code that had a constructor that using the configuration file.

         public XmlBase()
        {
            if (ConfigurationManager.ConnectionStrings  != null)
            {
                connectionString = ConfigurationManager.ConnectionStrings["dbConnectionString"].ConnectionString;
                con = new SqlConnection(connectionString);
            }
        }
 While testing it may seem that you need to override the constructor
to pass in some other information for testing.  But, with VSTS you
you just need to implement the same type of functionality like NUnit.
 1. Take the config file that you want to use in the test and copy it 
to where the dll is where the testing project created and rename
<project.dll>.config.
2. Test the code.
  For more information: 
https://blog.u2u.info/DottextWeb/peter/archive/2005/07/13/6179.aspx