在我将解决方案升级到 .NET 4.0 后,我最近遇到了集成测试问题——该问题的答案是获取 System.Data.SQLite.dll 的 64 位版本。
我已经想通了,但我有一个相关的问题。我的集成测试在我使用 Resharper 测试运行程序时执行,但在我使用 TestDriven.NET 测试运行程序时抛出异常:
Test 'MyApp.IntegrationTests.DataAccess.Providers.ContactFormSubmissionProviderTest.CanFetchContactFormSubmissionById' failed:
System.TypeInitializationException : The type initializer for 'MyApp.DataAccess.NHibernate.SessionManager' threw an exception.
----> NHibernate.HibernateException : Could not create the driver from NHibernate.Driver.SQLite20Driver.
----> System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
----> NHibernate.HibernateException : The IDbCommand and IDbConnection implementation in the assembly System.Data.SQLite could not be found. Ensure that the assembly System.Data.SQLite is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use <qualifyAssembly/> element in the application configuration file to specify the full name of the assembly.
at MyApp.DataAccess.NHibernate.SessionManager.OpenSession()
DataAccess\Providers\ContactFormSubmissionProviderTest.cs(28,0): at MyApp.IntegrationTests.DataAccess.Providers.ContactFormSubmissionProviderTest.CanFetchContactFormSubmissionById()
--HibernateException
at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings)
at NHibernate.Connection.ConnectionProvider.Configure(IDictionary`2 settings)
at NHibernate.Connection.ConnectionProviderFactory.NewConnectionProvider(IDictionary`2 settings)
at NHibernate.Cfg.SettingsFactory.BuildSettings(IDictionary`2 properties)
at NHibernate.Cfg.Configuration.BuildSettings()
at NHibernate.Cfg.Configuration.BuildSessionFactory()
NHibernate\SessionManager.cs(18,0): at MyApp.DataAccess.NHibernate.SessionManager..cctor()
--TargetInvocationException
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings)
--HibernateException
at NHibernate.Driver.ReflectionBasedDriver..ctor(String driverAssemblyName, String connectionTypeName, String commandTypeName)
at NHibernate.Driver.SQLite20Driver..ctor()
图片:
我还尝试了此链接中的解决方案;它没有帮助。如何从 Testdriven.Net 运行我的测试?
更新:
我的项目设置为任何 CPU,发布平台。
我的操作系统是 Windows 7 64 位。我已经链接了 x86 和 x64 版本的 SQLite。解释:
我的解决方案有几个项目——DataAccess、IntegrationTests、Core 和 UI。所有都是 .net 4.0 项目,并且都是类库,除了 UI,它是一个 MVC 3.0 项目。我正在使用 nUnit 2.4.8.0。我的 DataAccess 层使用 NHibernate。
- 我的 UI 项目引用 1.0.60.0(否则我无法从 VS2010 中运行我的应用程序)。
- 我的 IntegrationTests 项目引用 1.0.74.0(否则我无法使用 Resharper 的 TestRunner 运行我的测试)。
- 我的 DataAccess 项目引用 1.0.60.0,并且
- 我的核心项目不知道任何与数据库相关的知识。
1.0.60.0 是 x86,1.0.74.0 是 x64。
部署站点时,服务器需要 x86。
更新 2:
TestDriven.NET 有一个选项,因为它在工具 -> 选项 -> TestDriven.NET 下使用 32 位或 64 位进程。我将其更改为 64 位。现在,右键单击并选择“运行测试”将很好地执行它们,但我仍然遇到与“使用 NCover 测试”或“使用覆盖率测试”相同的问题,这是我真正想要完成的。