Visual Studio 2010 Unit Testing on Websites

Project A - Web Application/WebsiteProject B - Unit Test Application

I'm familiar how to do Unit Tests in multiple projects if it's something such as incrementCounter(ByRef nCounter As Integer) or getSquare(ByVal nValue As Integer). However, I'm being asked to create a Unit Test in Project B that calls a function in Project A and verifies a new record in a table. My issue is when I do so, it builds fine but has a runtime exception when trying to connect to the database (using a config file). My question is, do I need to have the same config file in Project B that is in Project A, or can Unit Testing a function in a website in this manner not be accomplished?

I would prefer to put the Unit Test in Project A but I don't have approval to do that at this moment (boss is on vacation and unreachable). I've also though of conditional statements to see if the function is being called by Unit Testing or through the browser, but that might be more work than is required. Any and all help is appreciated. Thanks.

UPDATE The actual error I'm getting is...

Class.Function-->The key 'OraConnection.ConnectionString' does not exist in the appSettings Configuration section.

I'm going to see if it's just a setting or if it's in the app.config file because I've copied it over to the other project, but am still getting the error. Thanks.

UPDATE 2 After looking around some more, Project A is a class library. However, I talked to a coworker and they informed me that the web.config files loads whatever settings are in the app.config file on launch. Also, none of the app.config files I have seem to have the database connection so it seems like a sourcing issue (or their clever way to keep things hidden). I'm trying to find a properly configured app.config file and then will test. Thanks everyone.


It uses the config file of the test project. So you need to place the connection string in the config file of the project that contains the test.

Also see answer to this question: Can someone provide a quick App.config/Web.config tutorial?

The big question is how does the Project B talk to Project A. Is Project A a dll that is referenced in Project B, or is Project A some kind of service which needs to be running separately. If it is the first case, you should not get be getting this error. If it is the second case, you should check that Project A is running when you run the unit test on Project B.

This probably doesn't answer your question very well, but I've found it much easier to abstract most of the logic to a business tier and unit test that. Even if you're using Entity Framework for your CRUD you can put your model in a business (or data or whatever) tier and unit test your functions.

Right now we are developing an aspx/silverlight app using EF 4 and have the model and Domain Services in a business project. It not only makes things easier to test, but we can share the same logic between the web and separate windows services that are running on the server.

Need Your Help

BlocksKit and Xcode 4.5

ios xcode

I've just updated to Xcode 4.5 an am getting this error

Objective-C/Cocos2D - Display different Sprites with Animation on the same positon on the Screen

objective-c cocos2d-iphone

Hello i have a big question and i don't find a way to solve my problem till now.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.