NUnit:是否可以从我的应用程序中引用类?

发布于 2024-11-10 16:42:31 字数 722 浏览 2 评论 0原文

我最近遇到了 Visual Studio 2008 测试框架的问题:使用 VS 无法测试 64 位 dll 2008 年。我有一个仅编译为 x64 的项目,我需要为该项目创建一些单元测试,但我无法使用 VS2008 测试框架来执行此操作。

随后,我下载了最新的 NUnit 框架(据我所知,它支持 x64 测试),但现在我尝试复制 Visual Studio 与其测试框架相同的行为。也就是说,我想在我的项目中定义的文本装置中实例化类。

下面是一个示例:

  • 我有一个项目(称为 MyProject),它编译为可执行文件: MyProject.exe
  • MyProject 中有一个名为 MyClass 的类。
  • 我有一个单独的测试项目,名为 MyProjectTest,它编译为 dll(因此我可以使用 NUnit 运行它)。
  • 如何在 MyProjectTest 中实例化 MyClass

据我了解,NUnit 似乎是为测试 DLL 而不是 EXE 而设计的,那么如果我想测试 EXE 中的类,我该怎么办?反射?我认为这就是 VS2008 的测试框架访问类的方式......

I recently ran into a brick wall with Visual Studio 2008's testing framework: testing 64 bit dlls is not possible with VS 2008. I have a project that compiles to x64 only and I need to create some unit tests for the project and I can't use the VS2008 testing framework to do it.

Subsequently, I downloaded the latest NUnit framework (which as far as I understand supports x64 testing), but now I'm trying to duplicate the same behavior that Visual Studio had with its testing framework. Namely, I would like to instantiate classes within the text fixture that are defined in my project.

Here is an example:

  • I have a project (call it MyProject) that compiles to an executable: MyProject.exe
  • There is a class within MyProject that's called MyClass.
  • I have a separate project for my tests, called MyProjectTest, and it compiles to a dll (so I can run it with NUnit).
  • How can I instantiate MyClass inside MyProjectTest?

As far as I understand NUnit seems to be designed for testing DLLs not EXEs, so what do I have to do if I want to test classes within an EXE? Reflection? I assume that's how VS2008's testing framework gets access to the classes...

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

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

发布评论

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

评论(2

慕烟庭风 2024-11-17 16:42:31

如何在 MyProjectTest 中实例化 MyClass?

执行此操作的正常方法是让您的 MyProjectTest 项目包含对 MyProject 的引用

,但似乎大多数人不喜欢引用 exe 的想法,因此将在第三个 dll 中定义 MyClass,该 dll 被 MyProject 和我的项目测试

据我了解,NUnit 似乎是为测试 DLL 而不是 EXE 而设计的。

我必须承认,我的所有测试都在 dll 中,但 Nunit 添加程序集对话框的默认文件规范是 *.dll 和 *.exe,否则会建议。

How can I instantiate MyClass inside MyProjectTest?

The normal way to do this is for your MyProjectTest project to contain a reference to MyProject

But it seems most people don't like the idea of referencing an exe and hence would have MyClass defined in a third dll which is referenced by both the MyProject and MyProjectTest

As far as I understand NUnit seems to be designed for testing DLLs not EXEs.

I must admit, all my tests are in dlls, but the default filespec for the Nunit Add assembly dialog box is *.dll and *.exe which would suggest otherwise.

南风几经秋 2024-11-17 16:42:31

可执行文件和 DLL 几乎相同。虽然存在一些差异,但不应该成为从 NUnit 测试项目引用可执行文件的障碍。

An executable and a DLL are nearly identical. There are some differences, but none that should serve as a hindrance to referencing an executable from your NUnit test project.

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