Testing - Connection string is missing

Excellent this worked for me. I have added App.config file under unit test project. But make sure that we shoud follow the synatx otherwise it will throw exception.

<connectionStrings>

    <add name="test" connectionString="" providerName="System.Data.SqlClient" />

    <add name="db" connectionString=""" providerName="System.Data.SqlClient"/>

</connectionStrings>


Add an App.config file to your unit testing project and copy over the connection string from the Web.config.

Update: Better Solution

While adding a config will solve the immediate problem, it still results in unit tests depending on an actual database connection, which is not great. The better way to solve this problem is to mock the DAL entirely and pass that into the services which are using it.

Microsoft provides some guidance on that here. It takes a little more time to setup, but it allows tests to be much more contained and complete.

I have had success using MockQueryable for mocking individual tables within a test data context.


Add a connection string in the unit test's app.config file. The unit test project isn't going to have access to your web project's web config.