C# ASP.NET集成测试-TestDrive.NET赢得';不要运行它们,其他测试运行者将运行它们

C# ASP.NET集成测试-TestDrive.NET赢得';不要运行它们,其他测试运行者将运行它们,c#,asp.net,sqlite,nunit,testdriven.net,C#,Asp.net,Sqlite,Nunit,Testdriven.net,在我将解决方案升级到.NET 4.0之后,我最近进行了集成测试——这个问题的答案是获取64位版本的System.Data.SQLite.dll 我已经弄明白了,但我有一个相关的问题。我的集成测试在使用Resharper testrunner时执行,但在使用TestDriven.NET testrunner时引发异常: Test 'MyApp.IntegrationTests.DataAccess.Providers.ContactFormSubmissionProviderTest.CanFet

在我将解决方案升级到.NET 4.0之后,我最近进行了集成测试——这个问题的答案是获取64位版本的System.Data.SQLite.dll

我已经弄明白了,但我有一个相关的问题。我的集成测试在使用Resharper testrunner时执行,但在使用TestDriven.NET testrunner时引发异常:

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()
测试“MyApp.IntegrationTests.DataAccess.Providers.ContactFormSubmissionProviderTest.CanFetchContactFormSubmissionById”失败:
System.TypeInitializationException:“MyApp.DataAccess.NHibernate.SessionManager”的类型初始值设定项引发异常。
---->NHibernate.HibernateException:无法从NHibernate.driver.SQLite20Driver创建驱动程序。
---->System.Reflection.TargetInvocationException:调用的目标已引发异常。
---->NHibernate.HibernateeException:在程序集System.Data.SQLite中找不到IDbCommand和IDbConnection实现。确保程序集System.Data.SQLite位于应用程序目录或全局程序集缓存中。如果程序集位于GAC中,请使用应用程序配置文件中的元素指定程序集的全名。
在MyApp.DataAccess.NHibernate.SessionManager.OpenSession()中
DataAccess\Providers\ContactFormSubmissionProviderTest.cs(28,0):在MyApp.IntegrationTests.DataAccess.Providers.ContactFormSubmissionProviderTest.CanFetchContactFormSubmissionById()中
--冬眠异常
位于NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2设置)
在NHibernate.Connection.ConnectionProvider.Configure处(IDictionary`2设置)
位于NHibernate.Connection.ConnectionProviderFactory.NewConnectionProvider(IDictionary`2设置)
在NHibernate.Cfg.SettingsFactory.BuildSettings(IDictionary`2属性)中
在NHibernate.Cfg.Configuration.BuildSettings()中
在NHibernate.Cfg.Configuration.BuildSessionFactory()中
NHibernate\SessionManager.cs(18,0):位于MyApp.DataAccess.NHibernate.SessionManager..cctor()
--目标异常
在System.RuntimeTypeHandle.CreateInstance(RuntimeType类型、Boolean publicOnly、Boolean noCheck、Boolean&canBeCached、RuntimeMethodHandleInternal&ctor、Boolean&bNeedSecurityCheck)
位于System.RuntimeType.CreateInstanceSlow(布尔publicOnly、布尔skipCheckThis、布尔fillCache)
位于System.RuntimeType.CreateInstanceDefaultCtor(布尔publicOnly、布尔skipVisibilityChecks、布尔skipCheckThis、布尔fillCache)
位于System.Activator.CreateInstance(类型,布尔非公共)
位于System.Activator.CreateInstance(类型)
位于NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2设置)
--冬眠异常
位于NHibernate.Driver.ReflectionBasedDriver..ctor(字符串驱动程序RassemblyName、字符串连接类型名称、字符串命令类型名称)
在NHibernate.Driver.SQLite20Driver..ctor()处
图像:

我也尝试了解决方案;这没用。如何从Testdriven.Net运行测试

更新:

我的项目被设置为构建为任何CPU、发布平台

我的操作系统是64位Windows 7。我已经链接了x86和x64版本的SQLite。说明:

我的解决方案有几个项目-DataAccess、IntegrationTests、Core和UI。它们都是.NET4.0项目,都是类库,但UI除外,它是一个MVC3.0项目。我正在使用NUnit2.4.8.0。我的数据访问层使用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有一个选项,它可以在Tools->Options->TestDriven.NET下使用32位或64位进程。我把它改成了64位。现在,右键单击并选择“运行测试”可以很好地执行它们,但我仍然存在“使用NCover进行测试”或“使用覆盖率进行测试”的相同问题,这正是我真正想要完成的。

我想您可能已经回答了您自己的问题:)

默认情况下,您提到的大多数运行程序将在x86模式下运行,您必须找到特定的实例,在这些实例中,您可以告诉某些运行程序(如TestDriven.net)使用x64在您的计算机上运行,但现在您遇到了NCover或Coverage的相同问题

因此,解决方案是强制项目基于x86构建。您的库将以x86为目标;ReSharper的runner将从解决方案中的构建配置中检测到这一点。因为您的目标生产机器是x86,所以没有问题。您可以在Win7 x64上运行x86目标程序集


转到解决方案配置,为每个项目选择x86的“目标平台”。从所有项目中引用x86 SQLite程序集。这就是我们在Win7x64开发机器上的几个项目上设置它的方式,其中NCrunch、R#、dotCover的行为都很好。

对SQLite程序集的引用是否配置了Copy Local to true?是的,它设置为Copy Local true。使用resharper的testrunner运行测试没有问题,但是当我使用td.net时,它无法连接OK,接下来的问题是,您的项目是否配置为构建任何CPU,x86或x64?您是否链接到SQLite的x86或x64版本?你的操作系统是32位还是64位?谢谢你。请检查上面的更新,我已经提供了这些信息,那么您是说您的集成测试使用64位版本的SQLite吗?TestDriven在32位环境中运行它们。