views:

31

answers:

1

Hello! I am trying to start unit testing an MVC2 project, which uses the Entity Framework. When I run my "hello world" test, it fails saying this:

The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.

How can I pass the connection data (which were generated by the Entity Framework and are in the main Web.config) to the testing project?

Thanks

+3  A: 

Depending on what unit testing framework you use you could try adding an app.config to your test-project with the right settings for EF. This works with xUnit.Net and I'm pretty sure most other test-frameworks also support this.

For completeness I do need to warn you that tests that touch the database aren't unit-tests but integration tests. Those are useful too but can become a hassle to maintain when your code changes. It's usually a good idea to test small pieces of code in isolation, this gets around problems like you describe because you won't need to access the database at all.

Mendelt
Thanks a lot :) I copied the Web.config to the testing project, and renamed it to App.conf, now the test works. For what regards the unit testing, that was useful. I must tell you that here I am cheating. Inf act the website will be driven by the UI and a web service. I need to simulate several different sequential calls to that service, and check their results, and I thought of using the testing framework and force it to do some work for me :)
Palantir
Great to hear it worked! Happy testing :-)
Mendelt