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?

[1443 byte] By [mxmissile] at [2007-12-17]
# 1

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

MichaelKoltachev at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 2
Yes, that did the trick. Thanx for the tip.
mxmissile at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 3
Are you using Beta2 or RC? For RC (and RTM) this should not be needed.
dhoptonMSFT at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...

Visual Studio Team System

Site Classified