2

在我将解决方案升级到 .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()

图片: 例外,D'oh!

我还尝试了此链接中的解决方案;它没有帮助。如何从 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 测试”或“使用覆盖率测试”相同的问题,这是我真正想要完成的。

4

1 回答 1

2

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

您提到的大多数跑步者默认情况下将在 x86 模式下运行,您必须找到可以告诉某些跑步者(如 TestDriven.net)使用 x64 在您的机器上运行的特定实例,但现在您正在打NCover 或 Coverage 也有同样的问题。

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

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

于 2011-11-06T11:52:08.743 回答