1

Hello I have a UnitTest project, and I added multiple App.config files (never copied to the output directory). I have created runtestconfig files for different configuration I need.

<DeploymentItem filename="Config01\App.config" /> 

Each time I run the project using Mstest

mstest.exe /runconfig:Config01.testrunconfig /testcontainer:MyTests.dll

or using VS2008 active configuration, my tests fail. In solution output directory the App.config file never gets copied.

This is a test ex:

  [TestMethod]
  public void TestAge()
  {
     string value = ConfigurationManager.AppSettings["age"];
     Assert.AreEqual(value, "21");
  }

and this is the error:Assert.AreEqual failed. Expected:<(null)>. Actual:<21>.

What am I doing wrong?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Angela_SB
  • 249
  • 4
  • 12

1 Answers1

1

I have solved my problem using xml files instead of App.config. Now if I change the configuration and I run the tests both in VS or command line using MSTest I get the expected results. It seems it does not work using ConfigurationManager.AppSettings to read data from App.config files.

Angela_SB
  • 249
  • 4
  • 12