Question unit testing - accessing database / config file

liptonIcedTea

Well-known member
Joined
Jan 18, 2007
Messages
89
Programming Experience
1-3
Hi,
I'm using VS2005 and Enterprise Library for data access.

I am attempting to create a unit test that tests a function which uses
the Enterprise Library to access a SQL Server 2005 database.

When I run the unit test, it fails with this message:

Failed 00:00:00.0111656 2 Test method
myProject.mytest.ValidateBusinessRulesTest threw exception:
System.NullReferenceException: Object reference not set to an instance
of an object..

In the function being tested, it seems to fail on this line of code:

Dim db As Database = DatabaseFactory.CreateDatabase()

CreateDatabase is a shared function and this code works fine when I run
the application being tested alone. Both the application being tested
and the test project have a valid reference to the Enterprise Library
dll.

I have a feeling it's becuase it can't see my web.config file which is in my web project, but i have moved the contents of this to a web config file in my Unit Test project and still same error.

Does anyone know how I can get my test to run?
 
Back
Top