我在使用Microsoft Visual Studio 2005和Enterprise Library 3.1。使用NUnit時從App.Config讀取連接字符串的問題2.5.2
我有一個數據訪問層,這是一個單獨的視覺工作室類庫項目。我寫單元測試的另一個類庫,並試圖調用數據訪問方法,但我不斷收到
PSMCP.Dal.Tests.DataManagerTests.GetAAAReturnsDataReader:
System.NullReferenceException : Object reference not set to an instance of an object.
at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseMapper.MapName(String name, IConfigurationSource configSource)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp[TTypeToBuild](IReadWriteLocator locator, String idToBuild, Object existing, PolicyList[] transientPolicies)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp[T](IReadWriteLocator locator, IConfigurationSource configurationSource)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp[T](IConfigurationSource configurationSource)
at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.NameTypeFactoryBase`1.CreateDefault()
at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.CreateDatabase()
at PSMCP.Dal.PSMCPDataManager.GetAAACall(String searchStr, Int32 filterCategory, Int32 centerId) in C:\Documents and Settings\user1\My Documents\Visual Studio 2005\Projects\Test\AAA.Dal\DataManager.cs:line 61
at PSMCP.Dal.Tests.DataManagerTests.GetAAAReturnsDataReader() in C:\Documents and Settings\user1\My Documents\Visual Studio 2005\Projects\Test\PSMCP.Dal.Tests\DataManagerTests.cs:line 27
我猜DatabaseFactory.CreateDatabase()調用無法讀取App.Config中得到連接字符串。單元測試項目有一個有效的App.Config,其中包含連接字符串設置[由EntLib配置實用程序添加]。我創建了一個控制檯應用程序並添加了相同的App.Config,它可以從控制檯應用程序運行良好。我很困惑,爲什麼在從NUnit GUI runner運行時不能運行。
任何想法?
感謝, 矩陣M.
沒錯。請參閱http://stackoverflow.com/questions/666898/nunit-not-picking-up-app-settings/3608544#3608544 – abatishchev 2010-08-31 12:34:14
鏈接已損壞。任何機會的問題被重新命名或刪除? – craastad 2013-12-02 09:42:41