集成测试通过 NUnit Gui/Console 失败,但通过 IDE 中的 TestDriven

发布于 2024-08-12 02:26:33 字数 1732 浏览 3 评论 0原文

我通过 NHibernate.Driver.OracleDataClientDriver 驱动程序类对 Oracle 数据库使用 NHibernate。我有一个集成测试,当使用 TestDriven.net 通过 IDE 执行时,可以正确拉回预期数据。但是,当我通过 NUnit GUI 或控制台运行单元测试时,NHibernate 会抛出异常,指出它找不到 Oracle.DataAccess 程序集。显然,这会阻止我将集成测试作为 CI 流程的一部分来运行。

NHibernate.HibernateException: IDbCommand 和 IDbConnection 在议会中实施 无法找到 Oracle.DataAccess。 确保装配 Oracle.DataAccess 位于 应用程序目录或全局 程序集缓存。如果装配体位于 GAC,使用 应用程序中的元素 配置文件指定完整的 程序集名称。*

我尝试通过两种方式使程序集可用,将其复制到 bin\debug 文件夹中并在配置文件中添加元素。同样,这两种方法在 IDE 中通过 TestDriven 执行时都有效。通过 NUnit GUI/控制台执行时这两种方法都不起作用。

NUnit Gui 日志显示以下消息。

21:42:26,377 错误 [TestRunnerThread] ReflectHelper [(null)]-无法加载 类型 Oracle.DataAccess.Client.OracleConnection, Oracle.DataAccess。 System.BadImageFormatException:可以 不加载文件或程序集 'Oracle.DataAccess, 版本=2.111.7.20,文化=中立, PublicKeyToken=89b483f429c47342' 或 它的依赖项之一。一次尝试 被用来加载一个程序 格式不正确。

文件名:'Oracle.DataAccess, 版本=2.111.7.20,文化=中立, PublicKeyToken=89b483f429c47342' ---> System.BadImageFormatException:可以 不加载文件或程序集 “Oracle.DataAccess”或其之一 依赖关系。有人尝试 加载一个不正确的程序 格式。

文件名:“Oracle.DataAccess”

我正在 Windows 7 64 位上运行 NUnit 2.4.8、TestDriven.net 2.24 和 VS2008sp1。 Oracle 数据提供程序 v2.111.7.20、NHibernate v2.1.0.4。

有没有人遇到过这个问题,更好的是,解决了它?


狡猾,谢谢你的回复。但是,NUnit 测试运行程序使用了正确的配置文件,因为我通过从预期配置文件中提取已知值进行测试。

我假设这与我的配置有关,特别是与 Windows 7 一般版本或 64 位版本有关。我继续在构建服务器(W2k3 服务器)上安装/配置了 Oracle 客户端。我将测试移至构建服务器上并运行上述相同的场景,并且测试在所有情况下都按预期工作。

接下来,我在另外两个开发人员工作站(具有相同工具集版本的 Win XP 32 位)上运行了这些场景,并且测试在所有情况下都按预期工作。

我很困惑,但现在很满意。我可以通过 IDE 运行集成测试,并可以通过我们的 CI 自动化在构建服务器上执行它们。现在唯一的问题是我无法在我的开发工作站上测试自动化构建项目。

I am using NHibernate against an Oracle database with the NHibernate.Driver.OracleDataClientDriver driver class. I have an integration test that pulls back expected data properly when executed through the IDE using TestDriven.net. However, when I run the unit test through the NUnit GUI or Console, NHibernate throws an exception saying it cannot find the Oracle.DataAccess assembly. Obviously, this prevents me from running my integration tests as part of my CI process.

NHibernate.HibernateException : The
IDbCommand and IDbConnection
implementation in the assembly
Oracle.DataAccess could not be found.
Ensure that the assembly
Oracle.DataAccess is located in the
application directory or in the Global
Assembly Cache. If the assembly is in
the GAC, use
element in the application
configuration file to specify the full
name of the assembly.*

I have tried making the assembly available in two ways, by copying it into the bin\debug folder and by adding the element in the config file. Again, both methods work when executing through TestDriven in the IDE. Neither work when executing through NUnit GUI/Console.

The NUnit Gui log displays the following message.

21:42:26,377 ERROR [TestRunnerThread]
ReflectHelper [(null)]- Could not load
type
Oracle.DataAccess.Client.OracleConnection,
Oracle.DataAccess.
System.BadImageFormatException: Could
not load file or assembly
'Oracle.DataAccess,
Version=2.111.7.20, Culture=neutral,
PublicKeyToken=89b483f429c47342' or
one of its dependencies. An attempt
was made to load a program with an
incorrect format.

File name: 'Oracle.DataAccess,
Version=2.111.7.20, Culture=neutral,
PublicKeyToken=89b483f429c47342' --->
System.BadImageFormatException: Could
not load file or assembly
'Oracle.DataAccess' or one of its
dependencies. An attempt was made to
load a program with an incorrect
format.

File name: 'Oracle.DataAccess'

I am running NUnit 2.4.8, TestDriven.net 2.24 and VS2008sp1 on Windows 7 64bit. Oracle Data Provider v2.111.7.20, NHibernate v2.1.0.4.

Has anyone run into this issue, better yet, fixed it?


Sly, Thanks for the reply. However, the NUnit test runner was using the correct configuration file as I was testing by pulling a known value out of the expected configuration file.

I am assuming this has something to do with my configuration, specifically with either Windows 7 in general or the 64bit version. I went ahead and installed/configured the Oracle client on the build server (W2k3 Server). I moved the test onto the build server and ran the same scenarios described above and the tests worked as expected in all cases.

I followed this up by running through the scenarios on two of the other developer workstations (Win XP 32bit with same toolset versions) and the tests worked as expected in all cases.

I'm perplexed but satisfied for now. I can run my integration tests through the IDE and can execute them on the build server through our CI automation. Only problem now is I can't test the automation build project on my development workstation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

未央 2024-08-19 02:26:33

当我尝试运行使用 Oracle.DataAccess.dll(odp.net 版本 2.111.7.20)的应用程序时,出现此错误。我将 Oracle 11g 即时客户端与应用程序一起交付。在 64 位服务器上它会失败。但是,我发送的客户端程序集是 32 位的,因此我编译了一个将 CPU 标志设置为 32 位的应用程序版本,现在它工作正常。这是因为当您明确告诉服务器应用程序是 32 位时,服务器会在 wow64 模拟器中运行整个组件。

I was getting this error when I tried to run an application which used Oracle.DataAccess.dll (odp.net version 2.111.7.20). I was shipping the oracle 11g instant client alongside the application. On 64 bit servers it would fail. However, the client assemblies I was shipping were 32 bit so I compiled a version of the app with the CPU flag set 32-bit and now it works fine. This is because the server runs the entire component within the wow64 emulator when you tell it the app is 32bit explicitly.

新人笑 2024-08-19 02:26:33

我在配置 NHibernate 时遇到了类似的问题。问题是大多数测试运行程序都使用与测试 dll 一起放置的 app.config。但某些版本的 NUnit 却没有。这就是为什么您的系统在测试时处于未配置状态。您可以尝试从测试中手动配置 NHibernate。希望有帮助

I had a similar problem when configuring NHibernate. The thing is that most of test runners are using app.config that is placed with your tests dll. But some versions of NUnit don't. Thats why your system stays in not configured state for the tests. You can try to configure NHibernate mannually from the test. Hope it helps

看透却不说透 2024-08-19 02:26:33

我可能刚刚通过进入测试项目的构建设置并将平台目标从“任何 cpu”更改为“x86”,在本地计算机上解决了类似/相同的问题

I may have just solved a similar/same problem on my local machine by going into the build settings for the test project and changing platform target from "any cpu" to "x86"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文