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 =开发者_JAVA技巧 ConfigurationManager.AppSettings["age"];
Assert.AreEqual(value, "21");
}
and this is the error:Assert.AreEqual failed. Expected:<(null)>. Actual:<21>.
What am I doing wrong?
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.
精彩评论