gpt4 book ai didi

c# - ASP.NET 集成测试 - TestDrive.net 不会运行它们,其他测试运行者会

转载 作者:太空宇宙 更新时间:2023-11-03 11:30:52 25 4
gpt4 key购买 nike

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

我已经弄明白了,但我有一个相关的问题。我的集成测试在我使用 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()

图像: Exception, D'oh!

我也尝试了 this link 中的解决方案;它没有帮助。如何从 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。我的数据访问层使用 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:

在 Tools -> Options -> TestDriven.NET 下有一个 TestDriven.NET 选项,它使用 32 位或 64 位进程。我将其更改为 64 位。现在,右键单击并选择“运行测试”可以很好地执行它们,但我仍然遇到“使用 NCover 测试”或“使用覆盖率测试”的相同问题,这才是我真正想要完成的。

最佳答案

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

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

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

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

关于c# - ASP.NET 集成测试 - TestDrive.net 不会运行它们,其他测试运行者会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7841881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com