开发者

NUnit: is it possible to reference classes from my application?

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...


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜