App.config and Unit Tests
Can you not add a app.config file to a Unit Test project? Here is my app.config file in my unit test project:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="mycn" connectionString="server=myserver;Trusted_Connection=False;database=mydb;uid=username;pwd=password"/>
</connectionStrings>
</configuration>
And here is one of my unit tests:
[TestMethod]
public void ConnectionString()
{
string s = ConfigurationManager.ConnectionStrings [0].ConnectionString;
Assert.IsNotNull(s);
Debug.WriteLine(s);
}
The output is always this
"data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
I dont even have SqlExpress installed on my machine, where is it getting that from? What am I doing wrong?
Hello,
1) Why it may not pick up your run config. Please make sure that your test project's app.config file in the same dir as compiled test, the simplest way is to select app.config file in solution explorer, go to property window and specify "Copy to output directory" = true. Then if you are using VS 2005 Beta2 and later we will pick it up from there.
2) What this is coming from. .NET supports multiple layers of config files. There is one for your application, one for machine, and one for security. This SQLExpress option should come from something like c:\windows\microsoft.net\framework\v2.0...\machine.config.
Just try to do #1 and please let me know if this solves the problem.
Thanks,
Michael